Submission #89108

#TimeUsernameProblemLanguageResultExecution timeMemory
89108beso123Special graph (IZhO13_specialg)C++14
0 / 100
1050 ms1712 KiB
#include <bits/stdc++.h>
using namespace std;
int n,p[100001],q,d=1;
int used[100001],cnt=0;
int DFS(int v,int f){
    used[v]=d;
    if(v==f)
        return cnt;
        cnt++;
        if(p[v]!=0 && used[p[v]]!=d)
DFS(p[v],f);
else return -1;

}
vector <int > v;
int main(){
    cin>>n;

    for(int k=1;k<=n;k++)
        cin>>p[k];
    cin>>q;
    for(int k=1;k<=q;k++){
        int a;
        cin>>a;
        if(a==1){
            int b;
            cin>>b;
            p[b]=0;
        }
           if(a==2){
            int b,c;
            cin>>b>>c;
            d++;
            cnt=0;
cout<<DFS(b,c)<<endl;
        }
    }

    return 0;
}

Compilation message (stderr)

specialg.cpp: In function 'int DFS(int, int)':
specialg.cpp:7:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(v==f)
     ^~
specialg.cpp:9:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
         cnt++;
         ^~~
specialg.cpp:14:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...