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

using namespace std;

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

void Jerry (int n, int m, int j, int a[][10001], 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,t2,volt2,r,t1);
        }
    }
}

int main()
{
    int n,m,t,k,j[10001],e,x,y,o;
    int a[10001][10001];
    cin>>n>>m>>t>>k>>e;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<+n;j++) a[i][j]=0;
    }
    for (int i=1;i<=m;i++)
    {
        cin>>x>>y;
        a[x][y]=1;
        a[y][x]=1;
        cin>>o;
        if (o==2)
        {
            a[x][y]=2;
            a[y][x]=2;
        }
    }
    for (int i=1;i<=k;i++) cin>>j[i];
    int t1[10001];for (int i=1;i<=10000;i++) t1[i]=-1;
    bool volt1[10001];for (int i=1;i<=10000;i++) volt1[i]=0;
    Tom(n,m,t,a,t1,volt1,0);
    for (int i=1;i<=k;i++)
    {
        int t2[10001];for (int i=1;i<=10000;i++) t2[i]=-1;
        bool volt2[10001];for (int i=1;i<=10000;i++) volt2[i]=0;
        Jerry(n,m,j[i],a,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/027ms64836 KiB
3Runtime error0/432ms64600 KiB
4Runtime error0/432ms64328 KiB
5Runtime error0/432ms64164 KiB
6Runtime error0/432ms64104 KiB
7Runtime error0/430ms63872 KiB
8Runtime error0/432ms63632 KiB
9Runtime error0/432ms63416 KiB
10Runtime error0/432ms63384 KiB
11Runtime error0/432ms63400 KiB
12Runtime error0/432ms63376 KiB
13Runtime error0/430ms63384 KiB
14Runtime error0/432ms63288 KiB
15Runtime error0/427ms63072 KiB
16Runtime error0/430ms63068 KiB
17Runtime error0/426ms62824 KiB
18Runtime error0/430ms62828 KiB
19Runtime error0/430ms62820 KiB
20Runtime error0/430ms62816 KiB
21Runtime error0/430ms62824 KiB
22Runtime error0/430ms62824 KiB