241382026-02-04 19:13:16xxxTom és Jerry 1 (80)cpp17Wrong answer 4/80116ms6964 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long


signed main() {
    int n, m, t, p, e;
    cin >> n >> m >> t >> p >> e;
    vector<vector<array<int, 2> > > adj(n+1);
    for(int i = 1; i <= m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        adj[x].push_back({y, z});
        adj[y].push_back({x, z});
    }
    const int hm = 1000000000000000;
    vector<int> dist(n+1, hm), dist2(n+1, -hm), dist3(n+1, hm);

    queue<int> q;
    q.push(t);
    dist[t] = 0;

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

        for(auto [u, z] : adj[v]) {
            if (z == 2 && dist[u] == hm) {
                dist[u] = dist[v] + 1;
                q.push(u);
            }
        }
    }

    q.push(e);
    dist2[e] = hm;

    while(!q.empty()) {
        int v = q.front();
        q.pop();
        if (dist[v] != hm) dist2[v] = dist[v];

        for(auto [u, z] : adj[v]) {
            if (dist2[v] != -hm) {
                if(dist2[u] < dist2[v] - 1) {
                    dist2[u] = dist2[v] - 1;
                    q.push(u);
                }

            }

        }
    }

    for(int i = 1; i <= p; i++) {
        int x;
        cin >> x;
        cout << (dist2[x] > 0 ? "IGEN" : "NEM" ) << '\n';
    }



}

/*
9 11 6 3 1
1 2 1
1 3 1
2 4 1
3 4 2
3 5 2
4 7 1
3 5 2
5 6 2
6 8 1
7 9 1
8 9 1
7
8
9
*/

SubtaskSumTestVerdictTimeMemory
base4/80
1Accepted0/01ms508 KiB
2Wrong answer0/03ms332 KiB
3Wrong answer0/41ms316 KiB
4Wrong answer0/41ms316 KiB
5Wrong answer0/41ms316 KiB
6Wrong answer0/41ms316 KiB
7Wrong answer0/41ms508 KiB
8Wrong answer0/42ms464 KiB
9Wrong answer0/43ms316 KiB
10Wrong answer0/43ms756 KiB
11Wrong answer0/49ms972 KiB
12Accepted4/413ms1332 KiB
13Wrong answer0/421ms1844 KiB
14Wrong answer0/446ms3496 KiB
15Wrong answer0/464ms4524 KiB
16Wrong answer0/464ms5432 KiB
17Wrong answer0/4105ms6452 KiB
18Wrong answer0/467ms4660 KiB
19Wrong answer0/482ms5472 KiB
20Wrong answer0/479ms4916 KiB
21Wrong answer0/474ms4908 KiB
22Wrong answer0/4116ms6964 KiB