# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
89028 | 2018-12-10T08:35:09 Z | beso123 | 특수한 그래프 (IZhO13_specialg) | C++14 | 194 ms | 1704 KB |
#include <bits/stdc++.h> using namespace std; int n,p[100001],q,d=1; int used[10001]; 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; } int main(){ cin>>n; vector <int > v; 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++; v.push_back(DFS(b,c)); } } for(int k=0;k<v.size();k++) cout<<v[k]<<endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 376 KB | Output is correct |
2 | Correct | 9 ms | 560 KB | Output is correct |
3 | Correct | 12 ms | 560 KB | Output is correct |
4 | Correct | 24 ms | 560 KB | Output is correct |
5 | Correct | 12 ms | 560 KB | Output is correct |
6 | Correct | 85 ms | 808 KB | Output is correct |
7 | Correct | 84 ms | 808 KB | Output is correct |
8 | Correct | 85 ms | 820 KB | Output is correct |
9 | Correct | 76 ms | 840 KB | Output is correct |
10 | Correct | 87 ms | 840 KB | Output is correct |
11 | Incorrect | 194 ms | 1704 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |