107502024-04-11 09:21:30MagyarKendeSZLGTom és Jerry 1 (80)cpp17Time limit exceeded 64/80574ms14716 KiB
#include <bits/stdc++.h>
using namespace std;

int N, M, T, P, E, INF = 1e9;
vector<vector<array<int, 2>>> g;
vector<int> tom, jerry;

void bfs(int s, vector<int>& d, int min_w, int goal) {
    queue<int> q({s});
    d[s] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        if (u == goal) return;
        for (auto [v, w] : g[u]) {
            if (d[u] + 1 < d[v] && min_w <= w && d[u] + 1 < tom[v]) {
                d[v] = d[u] + 1;
                q.push(v);
            }
        }
    }
}

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

    cin >> N >> M >> T >> P >> E;

    g.resize(N + 1);
    tom.assign(N + 1, INF);
    while (M--) {
        int A, B, S;
        cin >> A >> B >> S;
    
        g[A].push_back({B, S});
        g[B].push_back({A, S});
    }

    bfs(T, tom, 2, 0);
    while (P--) {
        int K;
        cin >> K;
        jerry.assign(N + 1, INF);
        bfs(K, jerry, 1, E);
        cout << (jerry[E] < INF ? "IGEN\n" : "NEM\n");
    }
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1824 KiB
2Accepted0/04ms2100 KiB
3Accepted4/43ms2124 KiB
4Accepted4/43ms2476 KiB
5Accepted4/43ms2600 KiB
6Accepted4/43ms2784 KiB
7Accepted4/43ms3160 KiB
8Accepted4/43ms3392 KiB
9Accepted4/44ms3560 KiB
10Accepted4/44ms3988 KiB
11Accepted4/47ms4616 KiB
12Accepted4/48ms5296 KiB
13Accepted4/414ms5952 KiB
14Accepted4/424ms8524 KiB
15Accepted4/432ms9932 KiB
16Accepted4/437ms13288 KiB
17Accepted4/459ms14612 KiB
18Accepted4/432ms13620 KiB
19Time limit exceeded0/4563ms11132 KiB
20Time limit exceeded0/4569ms11952 KiB
21Time limit exceeded0/4574ms12124 KiB
22Time limit exceeded0/4561ms14716 KiB