67642023-12-19 07:49:05Attila27Tom és Jerry 1 (80)cpp17Runtime error 0/8032ms65080 KiB
#include <iostream>

using namespace std;

void Tom (int n, int m, int t, bool a[][100001], bool b[][100001], int t1[], bool volt1[], int r)
{
    t1[t]=r;
    volt1[t]=1;
    r++;
    for (int i=1;i<=n;i++)
    {
        if (b[t][i]==1 && (t1[i]>r+1 || t1[i]==-1) && volt1[i]==0)
        {
            Tom(n,m,i,a,b,t1,volt1,r);
        }
    }
}

void Jerry (int n, int m, int j, bool a[][100001], bool b[][100001], int t2[], bool volt2[], int r, int t1[])
{
    t2[j]=r;
    volt2[j]=1;
    r++;
    for (int i=1;i<=n;i++)
    {
        if (a[j][i]==1 && (t2[i]>r+1 || t2[i]==-1) && volt2[i]==0 && (r<t1[i] || t1[i]==-1))
        {
            Jerry(n,m,i,a,b,t2,volt2,r,t1);
        }
    }
}

int main()
{
    int n,m,t,k,j[10001],e,x,y,o;
    bool a[100001][100001],b[100001][100001];
    cin>>n>>m>>t>>k>>e;
    for (int i=1;i<=m;i++)
    {
        cin>>x>>y;
        a[x][y]=1;
        a[y][x]=1;
        cin>>o;
        if (o==2)
        {
            b[x][y]=1;
            b[y][x]=1;
        }
    }
    for (int i=1;i<=k;i++) cin>>j[i];
    int t1[100001];for (int i=1;i<=100000;i++) t1[i]=-1;
    bool volt1[100001];for (int i=1;i<=100000;i++) volt1[i]=0;
    Tom(n,m,t,a,b,t1,volt1,0);
    for (int i=1;i<=k;i++)
    {
        int t2[100001];for (int i=1;i<=100000;i++) t2[i]=-1;
        bool volt2[100001];for (int i=1;i<=100000;i++) volt2[i]=0;
        Jerry(n,m,j[i],a,b,t2,volt2,0,t1);
        if (t2[e]!=-1) cout<<"IGEN"<<endl;
        else cout<<"NEM"<<endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/80
1Runtime error0/032ms65080 KiB
2Runtime error0/026ms64836 KiB
3Runtime error0/432ms64600 KiB
4Runtime error0/427ms64360 KiB
5Runtime error0/427ms64128 KiB
6Runtime error0/432ms63892 KiB
7Runtime error0/430ms63660 KiB
8Runtime error0/432ms63436 KiB
9Runtime error0/432ms63184 KiB
10Runtime error0/426ms62952 KiB
11Runtime error0/428ms62888 KiB
12Runtime error0/426ms62652 KiB
13Runtime error0/429ms62580 KiB
14Runtime error0/426ms62568 KiB
15Runtime error0/429ms62556 KiB
16Runtime error0/426ms62552 KiB
17Runtime error0/426ms62320 KiB
18Runtime error0/429ms62248 KiB
19Runtime error0/429ms62244 KiB
20Runtime error0/429ms62244 KiB
21Runtime error0/429ms62252 KiB
22Runtime error0/426ms62024 KiB