답안 #89108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89108 2018-12-10T10:14:01 Z beso123 특수한 그래프 (IZhO13_specialg) C++14
0 / 100
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

specialg.cpp: In function 'int DFS(int, int)':
specialg.cpp:7:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(v==f)
     ^~
specialg.cpp:9:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
         cnt++;
         ^~~
specialg.cpp:14:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 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 -