78412024-01-11 12:57:49rennTom és Jerry 1 (80)cpp17Time limit exceeded 64/80569ms62628 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;
stack<int> path;

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, vector<int> &parents, vector<bool> &tud, int &j, int &c)
{
    nex = {};
    fill(jerrytav.begin(), jerrytav.end(), 200000);

    nex.push(j);
    jerrytav[j] = 0;
    parents[j] = -1;
    int a;

    while(!nex.empty())
    {
        int& curr = nex.front();
        path.emplace(curr);
        for(auto &x : jerry[curr])
        {
            if(jerrytav[x] > jerrytav[curr]+1 && jerrytav[curr]+1 < tomtav[x])
            {
                parents[x] = curr;
                if(x == c)
                {
                    a = x;
                    while(parents[a] != -1)
                    {
                        tud[a] = true;
                        a = parents[a];
                    }
                    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);
    vector<int> parents(n);
    vector<bool> tud(n, 0);

    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 || tud[j])
        {
            cout << "IGEN\n";
            continue;
        }
        cout << (jerrybejar(jerry, tom_tav, jerry_tav, parents, tud, j, e) ? "IGEN\n" : "NEM\n");
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1824 KiB
2Accepted0/04ms2464 KiB
3Accepted4/43ms2228 KiB
4Accepted4/43ms2444 KiB
5Accepted4/43ms2552 KiB
6Accepted4/43ms2668 KiB
7Accepted4/43ms2804 KiB
8Accepted4/44ms3048 KiB
9Accepted4/44ms3176 KiB
10Accepted4/44ms3588 KiB
11Accepted4/47ms4016 KiB
12Accepted4/410ms5424 KiB
13Accepted4/414ms6080 KiB
14Accepted4/428ms8892 KiB
15Accepted4/435ms9104 KiB
16Accepted4/446ms15596 KiB
17Accepted4/468ms14320 KiB
18Accepted4/437ms11756 KiB
19Time limit exceeded0/4547ms62628 KiB
20Time limit exceeded0/4527ms62604 KiB
21Runtime error0/4414ms62368 KiB
22Time limit exceeded0/4569ms27616 KiB