답안 #92880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92880 2019-01-05T11:57:31 Z emil_physmath 특수한 그래프 (IZhO13_specialg) C++17
0 / 100
1000 ms 3356 KB
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

int nei[100005];
bool used[100005];

int DFS(int u, int v, int curAns=0);
int main()
{
	int n, q;
	cin>>n;
	for (int u=1; u<=n; u++)
		cin>>nei[u];
	cin>>q;
	while (q--)
	{
		int type, u, v;
		cin>>type;
		if (type==1)
		{
			cin>>u;
			nei[u]=0;
		}
		else
		{
			cin>>u>>v;
			memset(used+1, 0, n);
			cout<<DFS(u, v)<<'\n';
		}
	}

	char I;
	cin >> I;
	return 0;
}

int DFS(int u, int v, int curAns)
{
	used[u]=true;
	if (u==v) return curAns;
	if (!nei[u] || used[nei[u]])
		return -1;
	int temp=DFS(nei[u], v);
	return temp==-1?-1:temp+1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 504 KB Output is correct
2 Correct 8 ms 376 KB Output is correct
3 Correct 9 ms 376 KB Output is correct
4 Correct 21 ms 504 KB Output is correct
5 Correct 10 ms 372 KB Output is correct
6 Correct 65 ms 632 KB Output is correct
7 Correct 65 ms 632 KB Output is correct
8 Correct 68 ms 732 KB Output is correct
9 Correct 63 ms 800 KB Output is correct
10 Correct 69 ms 632 KB Output is correct
11 Execution timed out 1079 ms 3356 KB Time limit exceeded
12 Halted 0 ms 0 KB -