45922023-03-30 10:36:41AblablablaTom és Jerry 1 (80)cpp17Time limit exceeded 64/80573ms11344 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();

            if(akt == e){
                break;
            }

            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";
        }

        while(!bejar.empty()){
            bejar.pop();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1832 KiB
2Accepted0/03ms2284 KiB
3Accepted4/42ms2320 KiB
4Accepted4/43ms2344 KiB
5Accepted4/43ms2420 KiB
6Accepted4/43ms2552 KiB
7Accepted4/43ms2924 KiB
8Accepted4/43ms2920 KiB
9Accepted4/44ms3200 KiB
10Accepted4/44ms3452 KiB
11Accepted4/47ms4152 KiB
12Accepted4/48ms4932 KiB
13Accepted4/413ms5488 KiB
14Accepted4/423ms7492 KiB
15Accepted4/432ms8800 KiB
16Accepted4/437ms10760 KiB
17Accepted4/456ms11344 KiB
18Accepted4/430ms9608 KiB
19Time limit exceeded0/4561ms6672 KiB
20Time limit exceeded0/4555ms6684 KiB
21Time limit exceeded0/4573ms6264 KiB
22Time limit exceeded0/4551ms7508 KiB