46052023-03-30 11:22:55AblablablaTom és Jerry 1 (80)cpp17Time limit exceeded 64/80574ms10640 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> tom(n + 1, INF);
    queue<int> bejar1;
    bejar1.push(t);
    int aktualis = 1;
    int kovi = 0;
    int melyseg = 0;
    vector<bool> bejart1(n + 1, false);
    while(!bejar1.empty()){
        int akt = bejar1.front();
        bejar1.pop();


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

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

    }

    map<int, bool> valaszok;

    for(int i = 0; i < p; i++){
        int a;
        cin >> a;
        if(valaszok.count(a) > 0){
            if(valaszok[a]){
                cout << "IGEN\n";
            } else{
                cout << "NEM\n";
            }
        } else{
            queue<int> bejar;
            bejar.push(a);
            aktualis = 1;
            kovi = 0;
            melyseg = 0;
            vector<bool> bejart(n + 1, false);
            bejart[a] = 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";
                valaszok[a] = true;
            } else{
                cout << "NEM\n";
                valaszok[a] = false;
            }
        }

        /*while(!bejar.empty()){
            bejar.pop();
        }*/
    }
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1740 KiB
2Accepted0/04ms2228 KiB
3Accepted4/43ms2080 KiB
4Accepted4/43ms2428 KiB
5Accepted4/43ms2396 KiB
6Accepted4/43ms2408 KiB
7Accepted4/43ms2432 KiB
8Accepted4/43ms2736 KiB
9Accepted4/44ms3020 KiB
10Accepted4/44ms3272 KiB
11Accepted4/47ms3976 KiB
12Accepted4/48ms4528 KiB
13Accepted4/413ms5276 KiB
14Accepted4/423ms7276 KiB
15Accepted4/432ms8168 KiB
16Accepted4/437ms10304 KiB
17Accepted4/457ms10640 KiB
18Accepted4/430ms8952 KiB
19Time limit exceeded0/4574ms6144 KiB
20Time limit exceeded0/4552ms6160 KiB
21Time limit exceeded0/4568ms5780 KiB
22Time limit exceeded0/4555ms7412 KiB