220362026-01-14 14:06:15hunzombiTom és Jerry 1 (80)cpp17Wrong answer 0/8048ms4360 KiB
#include <bits/stdc++.h>
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int INF = 1e9;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, t, p, e;
    cin >> n >> m >> t >> p >> e;

    vector<vector<pii>> adj(n + 1);

    for (int i=1; i <= m; i++) {
        int u, v, c;
        cin >> u >> v >> c;

        adj[u].PB({v, c});
        adj[v].PB({u, c});
    }

    vi qu(p);
    for (int &x : qu) cin >> x;

    vi dt(n + 1, INF);
    queue<int> q;
    dt[t] = 0;
    q.push(t);

    while (!q.empty()) {
        int x = q.front(); q.pop();
        for (pii ne : adj[x]) {
            if (ne.second == 2 && dt[ne.first] == INF) {
                dt[ne.first] = dt[x] + 1;
                q.push(ne.first);
            }
        }
    }

    vi lastSafeTime(n + 1, -1);
    vector<bool> safe(n + 1, false);

    lastSafeTime[e] = INF;
    q.push(e);

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

        for (pii& ne : adj[x]) {
            int k = ne.first;
            int next_time = lastSafeTime[x] - 1;
            if (next_time > lastSafeTime[k]) {
                lastSafeTime[k] = min(next_time, dt[k]);
                q.push(k);
            }
        }
    }

    /*for (int x : dt) cout << x << ' ';
    cout << '\n';
    for (int x : lastSafeTime) cout << x << ' ';
    */

    for (int q : qu) cout << ((lastSafeTime[q]) ? "IGEN" : "NEM") << '\n';

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/80
1Accepted0/01ms316 KiB
2Wrong answer0/02ms316 KiB
3Wrong answer0/41ms500 KiB
4Wrong answer0/41ms508 KiB
5Wrong answer0/41ms316 KiB
6Wrong answer0/41ms508 KiB
7Wrong answer0/41ms316 KiB
8Wrong answer0/42ms484 KiB
9Wrong answer0/42ms424 KiB
10Wrong answer0/42ms564 KiB
11Wrong answer0/44ms564 KiB
12Wrong answer0/46ms972 KiB
13Wrong answer0/410ms1296 KiB
14Wrong answer0/423ms2284 KiB
15Wrong answer0/432ms3512 KiB
16Wrong answer0/430ms3960 KiB
17Wrong answer0/448ms3856 KiB
18Wrong answer0/432ms2936 KiB
19Wrong answer0/435ms4160 KiB
20Wrong answer0/430ms3264 KiB
21Wrong answer0/426ms3508 KiB
22Wrong answer0/448ms4360 KiB