139062025-01-09 09:56:50RRoliTom és Jerry 1 (80)cpp17Time limit exceeded 64/80600ms5760 KiB
#include <bits/stdc++.h>
using namespace std;

int n, m, t, p, e;
vector<int> tL;
vector<vector<int>> szom, tszom;

int main() {
    cin >> n >> m >> t >> p >> e;
    tL.resize(n+1, -1);
    szom.resize(n+1, vector<int>(0));
    tszom.resize(n+1, vector<int>(0));

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

    queue<int> sor;
    sor.push(t);
    tL[t] = 0;
    while(!sor.empty()) {
        for(auto i : tszom[sor.front()]) {
            if(tL[i] == -1) {
                tL[i] = tL[sor.front()]+1;
                sor.push(i);
            }
        }
        sor.pop();
    }

    vector<bool> win(n+1, false), volt(n+1, false);
    win[e] = true;
    volt[e] = true;
    sor.push(e);
    while(!sor.empty()) {
        for(auto i : szom[sor.front()]) {
            if(volt[i] == -1 && tL[i] == -1) {
                win[i] = true;
                sor.push(i);
            }
            volt[i] = true;
        }
        sor.pop();
    }

	for(int i = 0; i < p; i++) {
		int k;
		cin >> k;

		queue<int> bsor;
		vector<int> L(n+1, -1);
		bsor.push(k);
		L[k] = 0;
		string jo = "NEM";

		while(!bsor.empty()) {
			if(win[bsor.front()]) {
				jo = "IGEN";
				break;
			}
			for(auto i : szom[bsor.front()]) {
				if(L[i] == -1 && (tL[i] == -1 || tL[i] > L[bsor.front()]+1)) {
					L[i] = L[bsor.front()]+1;
					bsor.push(i);
				}
			}
        	bsor.pop();
    	}

		cout << jo << '\n';
	}

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/01ms500 KiB
2Accepted0/03ms316 KiB
3Accepted4/41ms316 KiB
4Accepted4/41ms500 KiB
5Accepted4/41ms316 KiB
6Accepted4/41ms372 KiB
7Accepted4/42ms440 KiB
8Accepted4/43ms524 KiB
9Accepted4/43ms316 KiB
10Accepted4/44ms564 KiB
11Accepted4/49ms792 KiB
12Accepted4/414ms1184 KiB
13Accepted4/423ms1672 KiB
14Accepted4/446ms2980 KiB
15Accepted4/465ms3124 KiB
16Accepted4/475ms5760 KiB
17Accepted4/4119ms5088 KiB
18Accepted4/467ms3892 KiB
19Time limit exceeded0/4600ms5012 KiB
20Time limit exceeded0/4583ms4992 KiB
21Time limit exceeded0/4587ms3644 KiB
22Time limit exceeded0/4600ms5260 KiB