18702022-12-06 20:15:07kovacs.peter.18fTom és Jerry 1 (80)cpp11Elfogadva 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");
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base80/80
1Elfogadva0/03ms2112 KiB
2Elfogadva0/03ms2456 KiB
3Elfogadva4/42ms2392 KiB
4Elfogadva4/42ms2552 KiB
5Elfogadva4/42ms2632 KiB
6Elfogadva4/42ms2652 KiB
7Elfogadva4/42ms2852 KiB
8Elfogadva4/43ms3120 KiB
9Elfogadva4/43ms3264 KiB
10Elfogadva4/43ms3508 KiB
11Elfogadva4/46ms4116 KiB
12Elfogadva4/48ms5004 KiB
13Elfogadva4/413ms5596 KiB
14Elfogadva4/424ms7740 KiB
15Elfogadva4/432ms8824 KiB
16Elfogadva4/439ms10804 KiB
17Elfogadva4/450ms11156 KiB
18Elfogadva4/434ms9332 KiB
19Elfogadva4/437ms9728 KiB
20Elfogadva4/437ms9716 KiB
21Elfogadva4/430ms8612 KiB
22Elfogadva4/452ms11800 KiB