45902023-03-30 10:33:20AblablablaTom és Jerry 1 (80)cpp17Time limit exceeded 64/80575ms11324 KiB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
int INF = 1e9 + 7;

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

    int n, m, t, p, e;
    cin >> n >> m >> t >> p >> e;
    vector<vector<pii>> csucsok(n + 1, vector<pii>(0, {0, 0}));
    for(int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        csucsok[a].push_back(pii(b, c));
        csucsok[b].push_back(pii(a, c));
    }

    vector<int> kezdohelyek(p, 0);

    for(int i = 0; i < p; i++){
        cin >> kezdohelyek[i];
    }

    vector<int> tom(n + 1, INF);
    queue<int> bejar;
    bejar.push(t);
    int aktualis = 1;
    int kovi = 0;
    int melyseg = 0;
    vector<bool> bejart(n + 1, false);
    while(!bejar.empty()){
        int akt = bejar.front();
        bejar.pop();


        for(pii x : csucsok[akt]){
            if(x.second == 2 && tom[x.first] == INF && !bejart[x.first]){
                bejar.push(x.first);
                bejart[x.first] = true;
                kovi++;
            }
        }

        tom[akt] = min(tom[akt], melyseg);
        aktualis--;
        if(aktualis == 0){
            swap(aktualis, kovi);
            melyseg++;
        }

    }

    for(int i = 0; i < p; i++){
        bejar.push(kezdohelyek[i]);
        aktualis = 1;
        kovi = 0;
        melyseg = 0;
        bejart.assign(n + 1, false);
        bejart[bejar.front()] = true;
        while(!bejar.empty()){
            int akt = bejar.front();
            bejar.pop();

            for(pii x : csucsok[akt]){
                if(melyseg + 1 < tom[x.first] && !bejart[x.first]){
                    bejar.push(x.first);
                    bejart[x.first] = true;
                    kovi++;
                }
            }

            aktualis--;
            if(aktualis == 0){
                swap(aktualis, kovi);
                melyseg++;
            }

        }

        if(bejart[e]){
            cout << "IGEN\n";
        } else{
            cout << "NEM\n";
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1828 KiB
2Accepted0/04ms2280 KiB
3Accepted4/43ms2264 KiB
4Accepted4/43ms2496 KiB
5Accepted4/43ms2928 KiB
6Accepted4/43ms2900 KiB
7Accepted4/43ms3264 KiB
8Accepted4/43ms3256 KiB
9Accepted4/44ms3524 KiB
10Accepted4/44ms3656 KiB
11Accepted4/47ms4352 KiB
12Accepted4/48ms5132 KiB
13Accepted4/414ms5592 KiB
14Accepted4/424ms7600 KiB
15Accepted4/439ms8912 KiB
16Accepted4/441ms10928 KiB
17Accepted4/457ms11324 KiB
18Accepted4/437ms9372 KiB
19Time limit exceeded0/4574ms6416 KiB
20Time limit exceeded0/4572ms6748 KiB
21Time limit exceeded0/4575ms6208 KiB
22Time limit exceeded0/4555ms7476 KiB