18512022-12-05 12:01:07kovacs.peter.18fTom és Jerry 1 (80)cpp11Time limit exceeded 60/80573ms10892 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);
            }
        }
    }
    for (auto e : neighbourS) {
        for (auto f : e) cerr << f.first + 1 << " ";
        cerr << endl;
    }
    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
base60/80
1Accepted0/03ms1828 KiB
2Accepted0/014ms2292 KiB
3Accepted4/42ms2140 KiB
4Accepted4/42ms2312 KiB
5Accepted4/43ms2204 KiB
6Accepted4/44ms2340 KiB
7Accepted4/46ms2448 KiB
8Accepted4/416ms2892 KiB
9Accepted4/419ms2996 KiB
10Accepted4/417ms3160 KiB
11Accepted4/478ms3780 KiB
12Accepted4/4112ms4552 KiB
13Accepted4/4150ms5300 KiB
14Accepted4/4331ms7524 KiB
15Accepted4/4446ms8156 KiB
16Accepted4/4379ms10892 KiB
17Time limit exceeded0/4535ms6376 KiB
18Accepted4/4460ms9280 KiB
19Time limit exceeded0/4558ms6548 KiB
20Time limit exceeded0/4573ms6492 KiB
21Time limit exceeded0/4544ms5828 KiB
22Time limit exceeded0/4560ms7100 KiB