16292022-11-30 12:25:081478Tom és Jerry 1 (80)cpp11Time limit exceeded 64/80569ms16076 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    //ifstream cin("be.txt");
    int numberOfNodes, numberOfEdges, positionOfTom, numberOfTries, positionOfGoal;
    cin >> numberOfNodes >> numberOfEdges >> positionOfTom >> numberOfTries >> positionOfGoal;

    vector<vector<int>> tomList(numberOfNodes + 1, vector<int> (1)), 
    jerryList(numberOfNodes + 1, vector<int> (1));

    for (int i = 1; i <= numberOfEdges; i++)
    {
        int start, finish, mass;
        cin >> start >> finish >> mass;
        jerryList[start].push_back(finish);
        jerryList[finish].push_back(start);
        if (mass == 2)
        {
            tomList[start].push_back(finish);
            tomList[finish].push_back(start);
        }
    }

    int a;

    /// Tom BFS
    vector<int> tomDistance(numberOfNodes + 1);
    tomDistance[0] = 1;
    queue<int> q;
    tomDistance[positionOfTom] = 1;
    q.push(positionOfTom);
    while (!q.empty())
    {
        a = q.front();
        q.pop();
        for (int i = 1; i < tomList[a].size(); i++)
        {
            if (!tomDistance[tomList[a][i]])
            {
                tomDistance[tomList[a][i]] = tomDistance[a] + 1;
                q.push(tomList[a][i]);
            }
        }
    }

    ///for(int i=1; i<=numberOfNodes; i++) cout<<tomDistance[i]<<" ";

    /// Jerry BFS
    while (numberOfTries--)
    {
        int positionOfJerry;
        cin >> positionOfJerry;

        vector<int> jerryDistance(numberOfNodes + 1);
        q.push(positionOfJerry);
        jerryDistance[0] = 1;
        jerryDistance[positionOfJerry] = 1;

        while (!q.empty())
        {
            a = q.front();
            q.pop();

            for (int i = 1; i < jerryList[a].size(); i++)
            {
                if (!jerryDistance[jerryList[a][i]] && (tomDistance[jerryList[a][i]] == 0 || 
                jerryDistance[a] + 1 < tomDistance[jerryList[a][i]]))
                {
                    q.push(jerryList[a][i]);
                    jerryDistance[jerryList[a][i]] = jerryDistance[a] + 1;
                }
            }
        }

        if (jerryDistance[positionOfGoal] != 0)
            cout << "IGEN" << '\n';
        else
            cout << "NEM" << '\n';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1812 KiB
2Accepted0/04ms2356 KiB
3Accepted4/42ms2264 KiB
4Accepted4/42ms2424 KiB
5Accepted4/42ms2668 KiB
6Accepted4/42ms2876 KiB
7Accepted4/43ms2916 KiB
8Accepted4/44ms3220 KiB
9Accepted4/44ms3440 KiB
10Accepted4/44ms3744 KiB
11Accepted4/410ms4456 KiB
12Accepted4/416ms5904 KiB
13Accepted4/427ms6420 KiB
14Accepted4/450ms9540 KiB
15Accepted4/475ms10188 KiB
16Accepted4/486ms16076 KiB
17Accepted4/4119ms14324 KiB
18Accepted4/475ms12408 KiB
19Time limit exceeded0/4564ms8392 KiB
20Time limit exceeded0/4550ms8396 KiB
21Time limit exceeded0/4565ms7440 KiB
22Time limit exceeded0/4569ms8952 KiB