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

using namespace std;

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

int main()
{
    int n,m,t,k,j[10001],e,x,y,o;
    bool a[10001][10001],b[10001][10001];
    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[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,b,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,b,t2,volt2,0,t1);
        if (t2[e]!=-1) cout<<"IGEN"<<endl;
        else cout<<"NEM"<<endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/80
1Runtime error0/029ms65080 KiB
2Runtime error0/028ms64836 KiB
3Runtime error0/432ms64600 KiB
4Runtime error0/427ms64368 KiB
5Runtime error0/432ms64108 KiB
6Runtime error0/427ms64120 KiB
7Runtime error0/432ms64008 KiB
8Runtime error0/427ms63780 KiB
9Runtime error0/432ms63536 KiB
10Runtime error0/426ms63528 KiB
11Runtime error0/432ms63280 KiB
12Runtime error0/428ms63276 KiB
13Runtime error0/430ms63084 KiB
14Runtime error0/427ms62868 KiB
15Runtime error0/430ms62860 KiB
16Runtime error0/426ms62624 KiB
17Runtime error0/430ms62552 KiB
18Runtime error0/426ms62312 KiB
19Runtime error0/429ms62148 KiB
20Runtime error0/429ms62152 KiB
21Runtime error0/426ms62156 KiB
22Runtime error0/429ms62088 KiB