15522022-11-24 11:27:461478Tom és Jerry 1 (80)cpp11Time limit exceeded 64/80569ms14284 KiB
#include <bits/stdc++.h>

using namespace std;


int main()
{
    //ifstream cin("be.txt");
    int n, m, t, k, e;
    cin>>n>>m>>t>>k>>e;
    t--;
    e--;

    vector<vector<int>> tSzL(n),
    jSzL(n);

    for(int i=0; i<m; i++){
        int s, f, mass;
        cin>>s>>f>>mass;
        s--; f--;
        jSzL[s].push_back(f);
        jSzL[f].push_back(s);
        if(mass == 2){
            tSzL[s].push_back(f);
            tSzL[f].push_back(s);
        }
    }


    ///Tom szelessegi
    vector<int> tom(n, -1);
    queue<int> qT;
    qT.push(t);
    tom[t] = 0;
    while(!qT. empty()){
        int a = qT.front();
        qT.pop();
        for(int i=0; i<tSzL[a].size(); i++){
            if(tom[tSzL[a][i]] == -1){
                qT.push(tSzL[a][i]);
                tom[tSzL[a][i]] = tom[a]+1;
            }
        }
    }

    ///jerry szelesseg
    while(k--){
        int j; cin>>j;
        j--;
        vector<int> jerry(n, -1);
        queue<int> qJ;
        qJ.push(j);
        jerry[j] = 0;
        while(!qJ. empty()){
            int a = qJ.front();
            qJ.pop();
            for(int i=0; i<jSzL[a].size(); i++){
                if(jerry[jSzL[a][i]] == -1 && (tom[jSzL[a][i]]==-1 ||
                   jerry[a] + 1 < tom[jSzL[a][i]])){
                    qJ.push(jSzL[a][i]);
                    jerry[jSzL[a][i]] = jerry[a] + 1;
                }
            }
        }

        if(jerry[e] != -1) cout<<"IGEN"<<'\n';
        else cout<<"NEM"<<'\n';
    }




    return 0;
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1684 KiB
2Accepted0/04ms2104 KiB
3Accepted4/42ms2052 KiB
4Accepted4/42ms2260 KiB
5Accepted4/42ms2476 KiB
6Accepted4/42ms2680 KiB
7Accepted4/43ms3052 KiB
8Accepted4/44ms3056 KiB
9Accepted4/44ms3324 KiB
10Accepted4/44ms3500 KiB
11Accepted4/412ms3960 KiB
12Accepted4/414ms5144 KiB
13Accepted4/426ms6000 KiB
14Accepted4/448ms8544 KiB
15Accepted4/471ms8936 KiB
16Accepted4/476ms14284 KiB
17Accepted4/4115ms13368 KiB
18Accepted4/474ms11048 KiB
19Time limit exceeded0/4566ms7900 KiB
20Time limit exceeded0/4569ms7756 KiB
21Time limit exceeded0/4558ms6556 KiB
22Time limit exceeded0/4546ms8236 KiB