139872025-01-09 13:59:32RRoliTom és Jerry 1 (80)cpp17Wrong answer 8/80115ms5684 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;
    int ln = 0;
    while(!sor.empty()) {
        for(auto i : tszom[sor.front()]) {
            if(tL[i] == -1) {
                tL[i] = tL[sor.front()]+1;
                sor.push(i);
                ln = max(ln, tL[i]);
            }
        }
        sor.pop();
    }

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

    for(int i = 1; i <= n; i++) {
        L[i] = -1;
        if(tL[i] == ln && tL[i] > 0 && nextwin[i]) {
            sor.push(i);
            L[i] = ln;
        } else {
           nextwin[i] = false; 
        }
    }

    while(!sor.empty()) {
        win[sor.front()] = true;
        if(L[sor.front()] > 1)
            for(auto i : szom[sor.front()]) {
                if(!nextwin[i]) {
                    if(L[i] == -1) L[i] = L[sor.front()]-1;
                    else L[i] = min(L[i], L[sor.front()]-1);
                    nextwin[i] = true;
                    sor.push(i);
                }
            }
        sor.pop();
    }

    for(int i = 0; i < p; i++) {
        int k;
        cin >> k;
        if(win[k]) cout << "IGEN\n";
        else cout << "NEM\n";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base8/80
1Accepted0/01ms316 KiB
2Wrong answer0/03ms316 KiB
3Accepted4/41ms316 KiB
4Wrong answer0/41ms316 KiB
5Wrong answer0/41ms316 KiB
6Wrong answer0/41ms316 KiB
7Wrong answer0/42ms428 KiB
8Wrong answer0/42ms320 KiB
9Wrong answer0/43ms376 KiB
10Wrong answer0/43ms564 KiB
11Accepted4/49ms820 KiB
12Wrong answer0/413ms1332 KiB
13Wrong answer0/420ms1548 KiB
14Wrong answer0/448ms2952 KiB
15Wrong answer0/464ms3124 KiB
16Wrong answer0/470ms5684 KiB
17Wrong answer0/4107ms5192 KiB
18Wrong answer0/467ms3892 KiB
19Wrong answer0/479ms4872 KiB
20Wrong answer0/481ms4920 KiB
21Wrong answer0/472ms3636 KiB
22Wrong answer0/4115ms5136 KiB