# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89108 | beso123 | 특수한 그래프 (IZhO13_specialg) | C++14 | 1050 ms | 1712 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |