# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89102 | 2018-12-10T10:06:35 Z | beso123 | Special graph (IZhO13_specialg) | C++14 | 10 ms | 376 KB |
#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]); cnt++; } if(used[h]!=d) 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++; cout<<DFS(b,c); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |