Submission #30882

# Submission time Handle Problem Language Result Execution time Memory
30882 2017-07-30T08:23:38 Z cgiosy None (KOI16_treeM) C++14
22 / 100
589 ms 18056 KB
#include <bits/stdc++.h>
using namespace std;

int a, b, c, d, x, n, q;
int *root, *parent;
vector<int> *tree;
vector<int> *t;

void f(int i)
{
	root[i] = b;

	for(int j : tree[i])
		f(j);
}

int main()
{
	cin >> n >> q;
	parent = new int[n + 2]();
	root = new int[n + 2]();
	tree = new vector<int>[n + 2];

	for(int i = 2; i <= n; i++)
	{
		cin >> a;
		tree[a].push_back(i);
		parent[i] = a;
	}

	for(int i = 1, m = n + q; i < m; i++)
	{
		cin >> x;

		if(x == 0)
		{
			cin >> b;
			t = &tree[parent[b]];
			t->erase(remove(t->begin(), t->end(), b), t->end());
			f(b);
		}
		else
		{
			cin >> c >> d;
			cout << (root[c] == root[d] ? "YES" : "NO") << '\n';
		}
	}

	cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2152 KB Output is correct
2 Correct 6 ms 2152 KB Output is correct
3 Correct 3 ms 2020 KB Output is correct
4 Correct 6 ms 2020 KB Output is correct
5 Correct 6 ms 2020 KB Output is correct
6 Correct 3 ms 2020 KB Output is correct
7 Correct 0 ms 2020 KB Output is correct
8 Correct 6 ms 2020 KB Output is correct
9 Correct 3 ms 2020 KB Output is correct
10 Correct 3 ms 2020 KB Output is correct
11 Correct 0 ms 2020 KB Output is correct
12 Correct 0 ms 2020 KB Output is correct
13 Correct 6 ms 2152 KB Output is correct
14 Correct 3 ms 2020 KB Output is correct
15 Correct 3 ms 2152 KB Output is correct
16 Correct 3 ms 2152 KB Output is correct
17 Correct 6 ms 2152 KB Output is correct
18 Correct 6 ms 2152 KB Output is correct
19 Correct 3 ms 2152 KB Output is correct
20 Correct 13 ms 2152 KB Output is correct
21 Correct 0 ms 2152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2152 KB Output is correct
2 Correct 6 ms 2152 KB Output is correct
3 Correct 3 ms 2020 KB Output is correct
4 Correct 6 ms 2020 KB Output is correct
5 Correct 6 ms 2020 KB Output is correct
6 Correct 3 ms 2020 KB Output is correct
7 Correct 0 ms 2020 KB Output is correct
8 Correct 6 ms 2020 KB Output is correct
9 Correct 3 ms 2020 KB Output is correct
10 Correct 3 ms 2020 KB Output is correct
11 Correct 0 ms 2020 KB Output is correct
12 Correct 0 ms 2020 KB Output is correct
13 Correct 6 ms 2152 KB Output is correct
14 Correct 3 ms 2020 KB Output is correct
15 Correct 3 ms 2152 KB Output is correct
16 Correct 3 ms 2152 KB Output is correct
17 Correct 6 ms 2152 KB Output is correct
18 Correct 6 ms 2152 KB Output is correct
19 Correct 3 ms 2152 KB Output is correct
20 Correct 13 ms 2152 KB Output is correct
21 Correct 0 ms 2152 KB Output is correct
22 Runtime error 179 ms 2188 KB Execution timed out (wall clock limit exceeded)
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 589 ms 18056 KB Execution timed out (wall clock limit exceeded)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2152 KB Output is correct
2 Correct 6 ms 2152 KB Output is correct
3 Correct 3 ms 2020 KB Output is correct
4 Correct 6 ms 2020 KB Output is correct
5 Correct 6 ms 2020 KB Output is correct
6 Correct 3 ms 2020 KB Output is correct
7 Correct 0 ms 2020 KB Output is correct
8 Correct 6 ms 2020 KB Output is correct
9 Correct 3 ms 2020 KB Output is correct
10 Correct 3 ms 2020 KB Output is correct
11 Correct 0 ms 2020 KB Output is correct
12 Correct 0 ms 2020 KB Output is correct
13 Correct 6 ms 2152 KB Output is correct
14 Correct 3 ms 2020 KB Output is correct
15 Correct 3 ms 2152 KB Output is correct
16 Correct 3 ms 2152 KB Output is correct
17 Correct 6 ms 2152 KB Output is correct
18 Correct 6 ms 2152 KB Output is correct
19 Correct 3 ms 2152 KB Output is correct
20 Correct 13 ms 2152 KB Output is correct
21 Correct 0 ms 2152 KB Output is correct
22 Runtime error 179 ms 2188 KB Execution timed out (wall clock limit exceeded)
23 Halted 0 ms 0 KB -