78212024-01-11 11:57:01rennTom és Jerry 1 (80)cpp17Wrong answer 0/80476ms14076 KiB
#include <bits/stdc++.h>
#define GOTTAGOFAST cin.tie(0); ios::sync_with_stdio(0);

using namespace std;

typedef vector<vector<int>> adj;

queue<int> nex;

inline void tombejar(adj &tom, vector<int> &tomtav, int &t)
{
    nex.push(t);
    tomtav[t] = 0;

    while(!nex.empty())
    {
        int& curr = nex.front();
        for(auto &x : tom[curr])
        {
            if(tomtav[x] > tomtav[curr]+1)
            {
                nex.push(x);
                tomtav[x] = tomtav[curr]+1;
            }
        }
        nex.pop();
    }
}

inline bool jerrybejar(adj &jerry, vector<int> &tomtav, vector<int> &jerrytav, int &j, int &c)
{
    nex = {};
    fill(jerrytav.begin(), jerrytav.end(), 200000);

    nex.push(j);
    jerrytav[j] = 0;

    while(!nex.empty())
    {
        int& curr = nex.front();
        for(auto &x : jerry[curr])
        {
            if(jerrytav[x] > jerrytav[curr]+1 && jerrytav[curr]+1 < tomtav[x])
            {
                if(x == c) return true;
                nex.push(x);
                jerrytav[x] = jerrytav[curr]+1;
            }
        }
        nex.pop();
    }
    return false;
}

int main()
{
    GOTTAGOFAST

    int n, m, t, j, jp, e;
    int a, b, s;
    cin >> n >> m >> t >> jp >> e;
    e--;

    adj tom(n);
    vector<int> tom_tav(n, 200000);
    adj jerry(n);
    vector<int> jerry_tav(n);

    for(;m--;)
    {
        cin >> a >> b >> s;
        a--;
        b--;
        jerry[a].push_back(b);
        jerry[b].push_back(a);
        if(s == 2)
        {
            tom[a].push_back(b);
            tom[b].push_back(a);
        }
    }

    tombejar(tom, tom_tav, (--t));

    for(;jp--;)
    {
        cin >> j;
        j--;
        if(j == t)
        {
            cout << "NEM\n";
            continue;
        }
        if(j == e)
        {
            cout << "IGEN\n";
            continue;
        }
        cout << (jerrybejar(jerry, tom_tav, jerry_tav, t, e) ? "IGEN\n" : "NEM\n");
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/80
1Wrong answer0/03ms1824 KiB
2Wrong answer0/04ms2320 KiB
3Wrong answer0/43ms2284 KiB
4Wrong answer0/43ms2524 KiB
5Wrong answer0/43ms2736 KiB
6Wrong answer0/43ms2756 KiB
7Wrong answer0/43ms2804 KiB
8Wrong answer0/43ms2992 KiB
9Wrong answer0/44ms3228 KiB
10Wrong answer0/44ms3564 KiB
11Wrong answer0/47ms4244 KiB
12Wrong answer0/48ms5172 KiB
13Wrong answer0/414ms5772 KiB
14Wrong answer0/427ms8444 KiB
15Wrong answer0/434ms8740 KiB
16Wrong answer0/443ms14076 KiB
17Wrong answer0/457ms13344 KiB
18Wrong answer0/437ms10852 KiB
19Wrong answer0/4476ms13152 KiB
20Wrong answer0/4432ms13108 KiB
21Wrong answer0/4287ms10632 KiB
22Wrong answer0/4232ms13820 KiB