Submission #89031

# Submission time Handle Problem Language Result Execution time Memory
89031 2018-12-10T08:39:48 Z beso123 Special graph (IZhO13_specialg) C++14
0 / 100
1000 ms 1560 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++;
v.push_back(DFS(b,c));
        }
    }
    int g=v.size();
    for(int k=0;k<g;k++)
        cout<<v[k]<<endl;
    return 0;
}

Compilation message

specialg.cpp: In function 'int DFS(int, int)':
specialg.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 9 ms 376 KB Output is correct
2 Correct 9 ms 376 KB Output is correct
3 Correct 11 ms 424 KB Output is correct
4 Correct 25 ms 628 KB Output is correct
5 Correct 12 ms 628 KB Output is correct
6 Correct 78 ms 848 KB Output is correct
7 Correct 82 ms 1044 KB Output is correct
8 Correct 86 ms 1044 KB Output is correct
9 Correct 80 ms 1044 KB Output is correct
10 Correct 90 ms 1044 KB Output is correct
11 Execution timed out 1055 ms 1560 KB Time limit exceeded
12 Halted 0 ms 0 KB -