# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89108 | 2018-12-10T10:14:01 Z | beso123 | Special graph (IZhO13_specialg) | C++14 | 1000 ms | 1712 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 380 KB | Output is correct |
2 | Correct | 9 ms | 380 KB | Output is correct |
3 | Correct | 10 ms | 464 KB | Output is correct |
4 | Correct | 24 ms | 500 KB | Output is correct |
5 | Correct | 12 ms | 592 KB | Output is correct |
6 | Correct | 66 ms | 720 KB | Output is correct |
7 | Correct | 69 ms | 720 KB | Output is correct |
8 | Correct | 71 ms | 780 KB | Output is correct |
9 | Correct | 63 ms | 780 KB | Output is correct |
10 | Correct | 74 ms | 856 KB | Output is correct |
11 | Execution timed out | 1050 ms | 1712 KB | Time limit exceeded |
12 | Halted | 0 ms | 0 KB | - |