Submission #89129

# Submission time Handle Problem Language Result Execution time Memory
89129 2018-12-10T11:06:48 Z temoyanteladze Special graph (IZhO13_specialg) C++14
0 / 100
1000 ms 4408 KB
//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

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 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 552 KB Output is correct
5 Correct 12 ms 612 KB Output is correct
6 Correct 68 ms 612 KB Output is correct
7 Correct 76 ms 612 KB Output is correct
8 Correct 75 ms 816 KB Output is correct
9 Correct 68 ms 1140 KB Output is correct
10 Correct 74 ms 1440 KB Output is correct
11 Execution timed out 1057 ms 4408 KB Time limit exceeded
12 Halted 0 ms 0 KB -