132922025-01-07 12:28:25AGergoTom és Jerry 1 (80)cpp17Futási hiba 36/80593ms6196 KiB
#include <bits/stdc++.h>

using namespace std;
vector<int>TomTime;
vector<int>JerryTime;
vector<vector<int>> TomGraph;
vector<vector<int>> JerryGraph;

void TomSearch(int pos, int time)
{
    for(int x:TomGraph[pos])
    {
        if(TomTime[x] > time+1)
        {
            TomTime[x] = time+1;
            TomSearch(x,time+1);
        }
    }
}

void JerrySearch(int pos, int time)
{
    for(int x:JerryGraph[pos])
    {
        if(JerryTime[x] > time+1 && TomTime[x]>time+1)
        {
            JerryTime[x] = time+1;
            JerrySearch(x,time+1);
        }
    }
}

int main()
{
    cin.tie(0);
    iostream::sync_with_stdio(0);

    int pointCount,edgeCount,TomPos,tries,HolePos,e1,e2,width,JerryStart;
    cin >> pointCount >> edgeCount >> TomPos >> tries >> HolePos;
    TomTime.resize(pointCount,INT_MAX);
    JerryTime.resize(pointCount,INT_MAX);
    TomGraph.resize(pointCount+1,vector<int>());
    JerryGraph.resize(pointCount+1,vector<int>());
    vector<bool> ans(tries);

    vector<int> reset = JerryTime;
    for(int i = 0; i < edgeCount; i++)
    {
        cin >> e1 >> e2 >> width;

        if(width == 2)
        {
            TomGraph[e1].push_back(e2);
            TomGraph[e2].push_back(e1);
        }
        JerryGraph[e1].push_back(e2);
        JerryGraph[e2].push_back(e1);

    }

    TomSearch(TomPos,0);

    for(int i =0; i< tries; i++)
    {
        JerryTime = reset;
        cin >> JerryStart;
        JerrySearch(JerryStart,0);

        //cout << JerryTime[HolePos] << endl;

        if(JerryTime[HolePos] != INT_MAX)
        {
            ans[i] = true;
        }
        else
        {
            ans[i] = false;
        }

    }
    for(int c:ans)
    {
        if(c)
        {
            cout << "IGEN\n";
        }
        else
        {
            cout << "NEM\n";
        }

    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base36/80
1Elfogadva0/01ms316 KiB
2Elfogadva0/08ms564 KiB
3Futási hiba0/41ms316 KiB
4Elfogadva4/41ms316 KiB
5Elfogadva4/41ms316 KiB
6Elfogadva4/41ms316 KiB
7Elfogadva4/42ms316 KiB
8Elfogadva4/46ms316 KiB
9Elfogadva4/47ms568 KiB
10Elfogadva4/49ms564 KiB
11Elfogadva4/461ms820 KiB
12Elfogadva4/4483ms1332 KiB
13Időlimit túllépés0/4593ms1844 KiB
14Időlimit túllépés0/4583ms3380 KiB
15Időlimit túllépés0/4580ms3380 KiB
16Időlimit túllépés0/4583ms6196 KiB
17Időlimit túllépés0/4586ms6196 KiB
18Időlimit túllépés0/4583ms4404 KiB
19Időlimit túllépés0/4579ms5428 KiB
20Időlimit túllépés0/4575ms5524 KiB
21Időlimit túllépés0/4583ms3892 KiB
22Időlimit túllépés0/4579ms5940 KiB