37622023-03-02 20:52:00UnluckYTom és Jerry 1 (80)cpp11Time limit exceeded 4/80600ms9228 KiB
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> tom, jerry;
vector<int> tomtav;


vector<bool> seen, mego;


void dfs(int x, int mtom){

    if (seen[x]) return;
    seen[x] = true;


    int mtomuj;

    if (tomtav[x] == -1){
        mtomuj = max(-1, mtom-1); 
    }
    else if (mtom = -1){
        mtomuj = tomtav[x];
    }
    else {
        mtomuj = min(mtom-1, tomtav[x]);
    }

    if (mtomuj != 0) mego[x] = true;
    

    for (int i : jerry[x]){
        if (mtomuj != 0) dfs(i, mtomuj);
    }

    seen[x] = false;


}

int main(){


    int n, m, t, p, e; cin >> n >> m >> t >> p >> e;


    tom.assign(n+1, {});
    jerry.assign(n+1, {});
    tomtav.assign(n+1, -1);
    seen.assign(n+1, false);
    mego.assign(n+1, false);

    for (int i = 0; i < m; i++){
        int a, b, c; cin >> a >> b >> c;
        jerry[a].push_back(b);
        jerry[b].push_back(a);
        if (c == 2){
            tom[a].push_back(b);
            tom[b].push_back(a);
        }
    }

    queue<int> q;

    q.push(t);

    vector<bool> bfsseen(n+1, false);
    tomtav[t] = 0;

    while (!q.empty()){
        int x = q.front(); q.pop();
        //cout << x << endl;
        if (bfsseen[x]) {continue;}
        bfsseen[x] = true;

        for (int i : tom[x]){
            if (tomtav[i] == -1){tomtav[i] = tomtav[x]+1;}
            else {tomtav[i] = min(tomtav[i], tomtav[x]+1);}
            q.push(i);
            //cout << x << " " <<  i << endl;
        }


    }

    // for (int i : tomtav){
    //     cout << i << " ";
    // }

    dfs(e, -1);


    for (int i = 0; i < p; i++){
        int x; cin >> x;
        if (mego[x]) cout << "IGEN";
        else cout << "NEM";
        cout << endl;
    }


    return 0;
}

/*

9 11 6 3 1
1 2 1
1 3 1
2 4 1
3 4 2
3 5 2
4 7 1
5 7 1
5 6 2
6 8 1
7 9 1
8 9 1
7
8
9
*/
SubtaskSumTestVerdictTimeMemory
base4/80
1Accepted0/03ms1812 KiB
2Time limit exceeded0/0600ms1460 KiB
3Accepted4/43ms2276 KiB
4Wrong answer0/43ms2476 KiB
5Time limit exceeded0/4600ms2668 KiB
6Time limit exceeded0/4578ms2908 KiB
7Time limit exceeded0/4566ms3004 KiB
8Time limit exceeded0/4542ms2320 KiB
9Time limit exceeded0/4559ms3364 KiB
10Time limit exceeded0/4570ms2828 KiB
11Time limit exceeded0/4578ms3284 KiB
12Time limit exceeded0/4564ms3728 KiB
13Time limit exceeded0/4566ms4312 KiB
14Time limit exceeded0/4566ms5900 KiB
15Time limit exceeded0/4560ms6240 KiB
16Time limit exceeded0/4527ms8672 KiB
17Time limit exceeded0/4555ms9228 KiB
18Time limit exceeded0/4568ms7632 KiB
19Time limit exceeded0/4568ms8264 KiB
20Time limit exceeded0/4577ms8264 KiB
21Time limit exceeded0/4551ms6860 KiB
22Time limit exceeded0/4555ms9172 KiB