Submission #89129

#TimeUsernameProblemLanguageResultExecution timeMemory
89129temoyanteladzeSpecial graph (IZhO13_specialg)C++14
0 / 100
1057 ms4408 KiB
//outsider #include <bits/stdc++.h> #define ll long long using namespace std; vector<ll>parent; vector<ll>son; vector<ll>used; ll cnt=0; ll dfs(ll v,ll f) { cnt++; if (v==f)return cnt-1; if (son[v]==0) { return -1; } if (used[son[v]]==used[v]) return -1; else{ used[son[v]]=used[v]; v=son[v]; dfs(v,f); } } int main (){ ll n,m; cin>>n; parent.resize(n+1); son.resize(n+1); used.resize(n+1); for (ll i=1;i<=n;i++) { ll t; cin>>t; son[i]=t; parent[t]=i; } cin>>m; used.resize(n+1,0); for (ll i=1;i<=m;i++) { ll a; cin>>a; if (a==1) { ll t; cin>>t; son[t]=0; } if (a==2) { ll b,c; cin>>b>>c; cnt=0; used[b]=i; cout<<dfs(b,c)<<endl; } } return 0;}

Compilation message (stderr)

specialg.cpp: In function 'long long int dfs(long long int, long long int)':
specialg.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...