# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89103 | beso123 | Special graph (IZhO13_specialg) | C++14 | 0 ms | 0 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];
int DFS(int v,int h){
used[v]=d;
queue <int> q;
q.push(v);
int cnt=0;
while(!q.empty()){
v=q.front();
q.pop();
if(v==h){
return cnt;
}
used[v]=d;
if(used[p[v]]!=d && p[v]!=0)
q.push(p[v])<<endl;
cnt++;
}
if(used[h]!=d)
return -1;
}
int main(){
cin>>n;
for(int k=1;k<=n;k++)
cin>>p[k];
cin>>q;
for(int k=1;k<=q;k++){