107602024-04-11 13:48:33MagyarKendeSZLGTom és Jerry 1 (80)cpp17Accepted 80/80226ms16952 KiB
#include <bits/stdc++.h>
using namespace std;
int N, M, T, P, E, INF = 1e9;

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> N >> M >> T >> P >> E;

    vector<vector<int>> jg(N + 1), tg(N + 1);
    vector<int> tom(N + 1, INF);
    vector<bool> jerry(N + 1);

    while (M--) {
        int U, V, W;
        cin >> U >> V >> W;
        jg[U].push_back(V);
        jg[V].push_back(U);
        if (W == 2) {
            tg[U].push_back(V);
            tg[V].push_back(U);
        }
    }

    queue<int> q({T});
    tom[T] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (auto v : tg[u]) {
            if (tom[v] == INF) {
                tom[v] = tom[u] + 1;
                q.push(v);
            }
        }
    }

    jerry[E] = 1;
    priority_queue<array<int, 2>> pq;
    pq.push({tom[E], E});
    while (!pq.empty()) {
        auto [dist, u] = pq.top(); pq.pop();
        if (dist < 0) continue;
        jerry[u] = 1;
        for (int v : jg[u]) {
            if (!jerry[v]) {
                pq.push({min(tom[v] - 1, dist - 1), v});
            }
        }
    }

    while (P--) {
        int K;
        cin >> K;
        cout << (jerry[K] ? "IGEN" : "NEM") << '\n';
    }
}
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/03ms1828 KiB
2Accepted0/04ms2460 KiB
3Accepted4/43ms2236 KiB
4Accepted4/43ms2444 KiB
5Accepted4/43ms2680 KiB
6Accepted4/43ms2768 KiB
7Accepted4/43ms2812 KiB
8Accepted4/44ms3012 KiB
9Accepted4/44ms3064 KiB
10Accepted4/44ms3376 KiB
11Accepted4/417ms4188 KiB
12Accepted4/48ms4620 KiB
13Accepted4/428ms6052 KiB
14Accepted4/461ms9124 KiB
15Accepted4/4226ms16796 KiB
16Accepted4/443ms13904 KiB
17Accepted4/465ms13656 KiB
18Accepted4/485ms12008 KiB
19Accepted4/456ms12716 KiB
20Accepted4/448ms12384 KiB
21Accepted4/441ms10440 KiB
22Accepted4/4146ms16952 KiB