315992026-09-09 21:16:51Kristof0306Tom és Jerry 1 (80)cpp17Elfogadva 80/8046ms4268 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pair<int, int>>;
using vai = vector<array<int, 3>>;

#define x first
#define y second
#define all(x) x.begin(), x.end()

void solve() {
    int n, m, tom, p, jerry;
    cin >> n >> m >> tom >> p >> jerry;
    tom--; jerry--;
    vector<vpi> connect(n);
    for (int i = 0; i < m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        connect[u].push_back({v, w});
        connect[v].push_back({u, w});
    }
    vi tom_dist(n, INT_MAX);
    tom_dist[tom] = 0;
    queue<int> q;
    q.push(tom);
    int dist=0;
    while (!q.empty()) {
        dist++;
        int len = q.size();
        while (len--) {
            int node = q.front(); q.pop();
            for (pi nex : connect[node]) {
                if (nex.y == 1) continue;
                if (tom_dist[nex.x] == INT_MAX) {
                    tom_dist[nex.x] = dist;
                    q.push(nex.x);
                }
            }
        }
    }

    vi visited(n, 1);
    queue<pi> q2;
    q2.push({jerry, INT_MAX});
    visited[jerry] = INT_MAX;

    while (!q2.empty()) {
        int len = q2.size();
        while (len--) {
            pi node = q2.front(); q2.pop();
            for (pi nex : connect[node.x]) {
                if (visited[nex.x] < node.y) {
                    if (node.y <= 1) continue;
                    visited[nex.x] = node.y;
                    q2.push({nex.x, min(tom_dist[nex.x], node.y-1)});
                }
            }
        }
    }
    while (p--) {
        int in; cin >> in; in--;
        if (visited[in] > 1) {
            cout << "IGEN\n";
        } else {
            cout << "NEM\n";
        }
    }
}

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

    int t=1;
    //cin >> t;
    while (t--) {
        solve();
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base80/80
1Elfogadva0/01ms316 KiB
2Elfogadva0/02ms316 KiB
3Elfogadva4/41ms316 KiB
4Elfogadva4/41ms500 KiB
5Elfogadva4/41ms424 KiB
6Elfogadva4/41ms316 KiB
7Elfogadva4/41ms316 KiB
8Elfogadva4/42ms552 KiB
9Elfogadva4/42ms316 KiB
10Elfogadva4/42ms792 KiB
11Elfogadva4/44ms564 KiB
12Elfogadva4/46ms1076 KiB
13Elfogadva4/410ms1204 KiB
14Elfogadva4/421ms2224 KiB
15Elfogadva4/429ms2808 KiB
16Elfogadva4/432ms3856 KiB
17Elfogadva4/443ms4020 KiB
18Elfogadva4/432ms3124 KiB
19Elfogadva4/432ms3380 KiB
20Elfogadva4/429ms3332 KiB
21Elfogadva4/425ms3068 KiB
22Elfogadva4/446ms4268 KiB