29972023-02-07 13:49:09Tibi23Tom és Jerry 1 (80)cpp11Wrong answer 28/80572ms22100 KiB
#include <iostream>
#include <vector>

using namespace std;

bool benne_van(vector<int>  x, int szam){
    for(int i=0; i<x.size();i++){
        if(x[i]==szam)
            return true;
    }
    return false;
}


    vector<int> jerry[100001];

    vector<int> tom[100001];

    int lepesT[100001];
    int lepesJ[100001];


void bejar_sz(int x, int d){  //d a távolság kezdetben 0

   // if(lepesT[x]> d)
    if(lepesT[x]!=100001)
        return;

    lepesT[x]=d;

    for(int i=0; i<tom[x].size(); i++){
        bejar_sz(tom[x][i], d+1);
    }

}

    bool elkap=false;
    bool cel = false;
    int vege;

void bejar_sz_jerry(int x, int d){  //d a távolság kezdetben 0
    //cout<<vege<<" "<<x<<endl;
    if(x==vege){
        cel=true;
        return;
    }

    if(cel==true)
        return;
   /* if(elkap==true)
        return;*/

   // if(lepesT[x]> d)
    if(lepesJ[x]!=-1)
        return;

    lepesJ[x]=d;
    //cout<<lepesJ[x]<<"--"<<lepesT[x]<<endl;
    if (lepesT[x] <= lepesJ[x]){

        //elkap=true;
        return;
    }
    for(int i=0; i<jerry[x].size(); i++){
        bejar_sz_jerry(jerry[x][i], d+1);
    }

}



int main()
{
    int hely;
    int utak;
    int tom_start;
    int m;
    //int vege;

    cin>>hely;
    cin>>utak;
    cin>>tom_start;
    cin>>m;
    cin>>vege;

    //vector<int> jerry[hely+1];

   //vector<int> tom[hely+1];

    int honnan, hova, szelesseg;

    for(int i=0; i<utak; i++){
            cin>>honnan;
            cin>>hova;
            cin>>szelesseg;

            if(benne_van(jerry[honnan], hova)==false)
                    jerry[honnan].push_back(hova);

            if(benne_van(jerry[hova], honnan)==false)
                    jerry[hova].push_back(honnan);

            if(szelesseg==2){
                if(benne_van(tom[honnan], hova)==false)
                    tom[honnan].push_back(hova);

                if(benne_van(tom[hova], honnan)==false)
                    tom[hova].push_back(honnan);
            }

    }

   /* for(int i=1; i<=hely;i++ ){
        cout<<i<<"-bol kivezeto utak:";
        for(int j=0; j<tom[i].size(); j++){
            cout<<tom[i][j]<<" ";
        }
        cout<<endl;
    }*/
    for(int i=1; i<=hely;i++){
        lepesT[i]=100001   ;
        lepesJ[i]=-1   ;
    }

    bejar_sz(tom_start, 0);
   /* for(int i=1; i<=hely;i++){
        cout<<i<<" "<<lepesT[i]<<endl   ;
    }*/

    int proba;
    for(int i=0; i<m; i++)
    {
        for(int j=1; j<=hely;j++){
        lepesJ[j]=-1   ;
        }
        cin>>proba;
        //elkap=false;
        cel = false;
        bejar_sz_jerry(proba,0);
        if( cel == true){
            cout<<"IGEN"<<endl;
        }
        else{
            cout<<"NEM"<<endl;
        }
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base28/80
1Accepted0/06ms11312 KiB
2Wrong answer0/08ms11800 KiB
3Accepted4/46ms11452 KiB
4Accepted4/46ms11588 KiB
5Accepted4/48ms11960 KiB
6Wrong answer0/46ms12044 KiB
7Wrong answer0/47ms12272 KiB
8Wrong answer0/48ms12660 KiB
9Wrong answer0/49ms12852 KiB
10Wrong answer0/49ms13236 KiB
11Wrong answer0/417ms13716 KiB
12Accepted4/419ms14340 KiB
13Accepted4/428ms15364 KiB
14Accepted4/461ms17396 KiB
15Wrong answer0/475ms17476 KiB
16Wrong answer0/4108ms20096 KiB
17Wrong answer0/4140ms22100 KiB
18Accepted4/472ms18616 KiB
19Time limit exceeded0/4572ms11324 KiB
20Time limit exceeded0/4555ms11280 KiB
21Time limit exceeded0/4541ms10372 KiB
22Time limit exceeded0/4549ms12164 KiB