241392026-02-04 19:21:07xxxTom és Jerry 1 (80)cpp17Wrong answer 4/80114ms6940 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) {
            if (dist2[v] < hm/10) dist2[v] = max(dist2[v], dist[v]);
            else dist2[v] = dist[v];
        }

        for(auto [u, z] : adj[v]) {

            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/01ms316 KiB
2Wrong answer0/03ms564 KiB
3Wrong answer0/41ms316 KiB
4Wrong answer0/41ms316 KiB
5Wrong answer0/41ms316 KiB
6Wrong answer0/41ms316 KiB
7Wrong answer0/41ms316 KiB
8Wrong answer0/42ms316 KiB
9Wrong answer0/43ms572 KiB
10Wrong answer0/43ms564 KiB
11Wrong answer0/49ms836 KiB
12Accepted4/413ms1332 KiB
13Wrong answer0/421ms1844 KiB
14Wrong answer0/445ms3324 KiB
15Wrong answer0/464ms4524 KiB
16Wrong answer0/465ms5608 KiB
17Wrong answer0/4101ms6692 KiB
18Wrong answer0/465ms4780 KiB
19Wrong answer0/479ms4816 KiB
20Wrong answer0/476ms4772 KiB
21Wrong answer0/471ms4148 KiB
22Wrong answer0/4114ms6940 KiB