176882025-09-13 11:14:46TakacsAndrasTom és Jerry 1 (80)cpp17Accepted 80/80238ms6832 KiB
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m,t,p,e; cin >> n >> m >> t >> p >> e;
    vector<vector<pair<int,int>>> g(n+1);
    for (int i = 0; i < m; i++) {
        int a,b,c; cin >> a >> b >> c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    vector<int> p1(p);
    for (int &x : p1) cin >> x;
    vector<int> d1(n+1,1e6);
    queue<int> q1;
    d1[t] = 0;
    q1.push(t);
    while (!q1.empty()) {
        int u = q1.front();
        q1.pop();
        for (auto x : g[u]) {
            if (x.second == 2 && d1[x.first] == 1e6) {
                d1[x.first] = d1[u]+1;
                q1.push(x.first);
            }
        }
    }
    priority_queue<pair<int,int>> q2;
    q2.push({d1[e],e});
    vector<bool> d2(n+1);
    while (!q2.empty()) {
        int u = q2.top().second, d = q2.top().first;
        q2.pop();
        if (d <= 0) continue;
        d2[u] = true;
        for (auto x : g[u]) {
            if (!d2[x.first]) q2.push({min(d-1,d1[x.first]),x.first});
        }
    }
    for (int x : p1) {
        if (d2[x]) cout << "IGEN\n";
        else cout << "NEM\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/01ms316 KiB
2Accepted0/04ms316 KiB
3Accepted4/41ms316 KiB
4Accepted4/41ms316 KiB
5Accepted4/41ms316 KiB
6Accepted4/41ms508 KiB
7Accepted4/42ms316 KiB
8Accepted4/43ms508 KiB
9Accepted4/44ms316 KiB
10Accepted4/43ms500 KiB
11Accepted4/417ms1012 KiB
12Accepted4/412ms992 KiB
13Accepted4/434ms1540 KiB
14Accepted4/475ms2860 KiB
15Accepted4/4238ms6832 KiB
16Accepted4/467ms3892 KiB
17Accepted4/4104ms4344 KiB
18Accepted4/4104ms4028 KiB
19Accepted4/475ms3524 KiB
20Accepted4/471ms3380 KiB
21Accepted4/463ms3104 KiB
22Accepted4/4184ms6332 KiB