29952023-02-07 13:46:07Tibi23Tom és Jerry 1 (80)cpp11Wrong answer 0/80583ms22036 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]!=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(lepesJ[x]!=-1)
        return;

    lepesJ[x]=d;
  
    if (lepesT[x] <= lepesJ[x]){

        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;
 

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


    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++){
        lepesT[i]=100001   ;
        lepesJ[i]=-1   ;
    }

    bejar_sz(tom_start, 0);

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

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/80
1Wrong answer0/07ms11304 KiB
2Wrong answer0/08ms11724 KiB
3Wrong answer0/46ms11840 KiB
4Wrong answer0/46ms11912 KiB
5Wrong answer0/46ms12216 KiB
6Wrong answer0/46ms12020 KiB
7Wrong answer0/46ms12076 KiB
8Wrong answer0/47ms12164 KiB
9Wrong answer0/48ms12368 KiB
10Wrong answer0/48ms12448 KiB
11Wrong answer0/417ms12880 KiB
12Wrong answer0/419ms13632 KiB
13Wrong answer0/429ms14404 KiB
14Wrong answer0/457ms16568 KiB
15Wrong answer0/475ms16704 KiB
16Wrong answer0/4115ms19932 KiB
17Wrong answer0/4137ms22036 KiB
18Wrong answer0/472ms18676 KiB
19Time limit exceeded0/4582ms11156 KiB
20Time limit exceeded0/4565ms11272 KiB
21Time limit exceeded0/4556ms10164 KiB
22Time limit exceeded0/4583ms11896 KiB