18542022-12-05 14:26:12kovacs.peter.18fTom és Jerry 1 (80)cpp11Time limit exceeded 64/80600ms10940 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M, T, P, E;
    cin >> N >> M >> T >> P >> E;
    vector<vector<pair<int, int>>> neighbourS(N); // node, weihgt
    while (M--) {
        int A, B, S;
        cin >> A >> B >> S;
        --A;
        --B;
        neighbourS[A].push_back({ B, S });
        neighbourS[B].push_back({ A, S });
    }
    --T;
    --E;
    // szélességi bejárás Tomra
    vector<int> t_distS(N, -1);
    queue<int> currentS;
    t_distS[T] = 0;
    currentS.push(T);
    while (!currentS.empty()) {
        int c = currentS.front();
        currentS.pop();
        for (auto e : neighbourS[c]) {
            if (e.second == 2 && t_distS[e.first] == -1) {
                t_distS[e.first] = t_distS[c] + 1;
                currentS.push(e.first);
            }
        }
    }
    while (P--) {
        int K;
        cin >> K;
        --K;
        // szélességi bejárás Jerryre
        vector<int> j_distS(N, -1);
        j_distS[K] = 0;
        currentS.push(K);
        while (!currentS.empty()) {
            int c = currentS.front();
            currentS.pop();
            for (auto e : neighbourS[c]) {
                if (j_distS[e.first] == -1 && (t_distS[e.first] == -1 || t_distS[e.first] > j_distS[c] + 1)) {
                    j_distS[e.first] = j_distS[c] + 1;
                    currentS.push(e.first);
                }
            }
        }
        cout << (j_distS[E] == -1 ? "NEM\n" : "IGEN\n");
    }
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1828 KiB
2Accepted0/03ms2432 KiB
3Accepted4/42ms2272 KiB
4Accepted4/42ms2544 KiB
5Accepted4/42ms2452 KiB
6Accepted4/42ms2652 KiB
7Accepted4/42ms2884 KiB
8Accepted4/43ms2904 KiB
9Accepted4/43ms3180 KiB
10Accepted4/43ms3484 KiB
11Accepted4/46ms3992 KiB
12Accepted4/48ms4436 KiB
13Accepted4/414ms4948 KiB
14Accepted4/423ms7304 KiB
15Accepted4/437ms8008 KiB
16Accepted4/439ms10672 KiB
17Accepted4/459ms10940 KiB
18Accepted4/437ms9440 KiB
19Time limit exceeded0/4600ms6152 KiB
20Time limit exceeded0/4564ms6404 KiB
21Time limit exceeded0/4573ms6180 KiB
22Time limit exceeded0/4577ms7684 KiB