220382026-01-14 14:08:45hunzombiTom és Jerry 1 (80)cpp17Time limit exceeded 0/80591ms32000 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, INF);
    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
1Time limit exceeded0/0583ms508 KiB
2Runtime error0/0340ms32000 KiB
3Time limit exceeded0/4583ms316 KiB
4Runtime error0/4153ms32000 KiB
5Runtime error0/4150ms32000 KiB
6Runtime error0/4216ms32000 KiB
7Runtime error0/4263ms32000 KiB
8Runtime error0/4402ms32000 KiB
9Runtime error0/4358ms32000 KiB
10Runtime error0/4280ms32000 KiB
11Runtime error0/4221ms32000 KiB
12Time limit exceeded0/4591ms31392 KiB
13Runtime error0/4430ms32000 KiB
14Runtime error0/4439ms32000 KiB
15Runtime error0/4310ms32000 KiB
16Time limit exceeded0/4588ms19652 KiB
17Runtime error0/4404ms32000 KiB
18Runtime error0/4405ms32000 KiB
19Runtime error0/4293ms32000 KiB
20Time limit exceeded0/4591ms25140 KiB
21Runtime error0/4395ms32000 KiB
22Runtime error0/4323ms32000 KiB