This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |