45782023-03-30 09:44:00AblablablaTom és Jerry 1 (80)cpp17Wrong answer 32/80568ms11700 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 = -1;
    while(!bejar.empty()){
        int akt = bejar.front();
        bejar.pop();

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

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

        tom[akt] = melyseg;
    }

    vector<bool> bejart;

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


        /*int akt = bejar.front();
        bejar.pop();
        bejart[akt] = 1;
        cout << "kor: " << i + 1 << " akt: " << akt << " melyseg: " << melyseg << "\n";

        for(pii x : csucsok[akt]){
            if(!bejart[x.first]){
                bejar.push(x.first);
                kovi++;
            }
        }

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



        while(!bejar.empty()){
            int akt = bejar.front();
            bejar.pop();

            if(melyseg + 1 < tom[akt]){
                bejart[akt] = 1;
            }

            if(akt == e && melyseg + 1 < tom[akt]){
                break;
            }


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

                //cout << akt << " " << melyseg + 1 << " " << bejar.size() << "\n";
            }
            aktualis--;
            if(aktualis == 0){
                swap(aktualis, kovi);
                melyseg++;
            }
        }

        if(bejart[e]){
            cout << "IGEN\n";
        } else{
            cout << "NEM\n";
        }

        while(!bejar.empty()){
            bejar.pop();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base32/80
1Accepted0/03ms1824 KiB
2Accepted0/04ms2248 KiB
3Wrong answer0/43ms2232 KiB
4Accepted4/43ms2448 KiB
5Wrong answer0/43ms2664 KiB
6Accepted4/43ms2876 KiB
7Wrong answer0/43ms2992 KiB
8Accepted4/44ms3292 KiB
9Accepted4/44ms3516 KiB
10Wrong answer0/44ms3904 KiB
11Accepted4/48ms4396 KiB
12Wrong answer0/410ms5048 KiB
13Wrong answer0/414ms5844 KiB
14Accepted4/426ms7880 KiB
15Accepted4/443ms8924 KiB
16Accepted4/441ms10800 KiB
17Wrong answer0/475ms11700 KiB
18Wrong answer0/434ms9596 KiB
19Time limit exceeded0/4561ms6652 KiB
20Time limit exceeded0/4568ms6480 KiB
21Time limit exceeded0/4547ms6312 KiB
22Time limit exceeded0/4560ms7940 KiB