18702022-12-06 20:15:07kovacs.peter.18fTom és Jerry 1 (80)cpp11Accepted 80/8052ms11800 KiB
#include <iostream>
#include <algorithm>
#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); // push in pqS, if has -2 distance neihbour
    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);
            }
        }
    }
    vector<int> e_distS(N, -1);
    if (t_distS[E] == -1) {
        e_distS[E] = 100000;
    }
    priority_queue<pair<int, int>> pqS; // distance, node
    pqS.push({ e_distS[E], E });
    while (!pqS.empty()) {
        pair<int, int> c = pqS.top();
        pqS.pop();
        for (auto e : neighbourS[c.second]) {
            if (e_distS[e.first] == -1) {
                int d = c.first ? c.first - 1 : 0;
                e_distS[e.first] = t_distS[e.first] == -1 ? d : min(d, t_distS[e.first]);
                pqS.push({ e_distS[e.first], e.first });
            }
        }
    }
    while (P--) {
        int K;
        cin >> K;
        --K;
        cout << (e_distS[K] ? "IGEN\n" : "NEM\n");
    }
}
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/03ms2112 KiB
2Accepted0/03ms2456 KiB
3Accepted4/42ms2392 KiB
4Accepted4/42ms2552 KiB
5Accepted4/42ms2632 KiB
6Accepted4/42ms2652 KiB
7Accepted4/42ms2852 KiB
8Accepted4/43ms3120 KiB
9Accepted4/43ms3264 KiB
10Accepted4/43ms3508 KiB
11Accepted4/46ms4116 KiB
12Accepted4/48ms5004 KiB
13Accepted4/413ms5596 KiB
14Accepted4/424ms7740 KiB
15Accepted4/432ms8824 KiB
16Accepted4/439ms10804 KiB
17Accepted4/450ms11156 KiB
18Accepted4/434ms9332 KiB
19Accepted4/437ms9728 KiB
20Accepted4/437ms9716 KiB
21Accepted4/430ms8612 KiB
22Accepted4/452ms11800 KiB