#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 1e5+10;
vector<int> tree[mxn];
vector<int> eul;
int par[mxn][20],dep[mxn];
int N,Q;
int rt;
int dp[mxn];
int dfn[mxn];
set<int> st;
void dfs(int now){
for(int i = 1;i<20;i++)par[now][i] = par[par[now][i-1]][i-1];
sort(tree[now].begin(),tree[now].end());
for(auto nxt:tree[now]){
dep[nxt] = dep[now]+1;
dfs(nxt);
}
dfn[now] = eul.size();
eul.push_back(now);
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>Q;
for(int i = 1;i<=N;i++){
int p;
cin>>p;
par[i][0] = p;
tree[p].push_back(i);
if(!p)rt = i;
}
par[rt][0] = rt;
dfs(rt);
for(int i = 0;i<N;i++)st.insert(i);
while(Q--){
int t,k;
cin>>t>>k;
int lst = 0;
if(t == 1){
while(k--){
assert(!st.empty());
lst = *st.begin();
st.erase(st.begin());
dp[eul[lst]] = true;
}
cout<<eul[lst]<<'\n';
}
else{
lst = k;
for(int i = 19;i>=0;i--){
if(dp[par[lst][i]])lst = par[lst][i];
}
dp[lst] = false;
st.insert(dfn[lst]);
cout<<dep[k]-dep[lst]<<'\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5464 KB |
Output isn't correct |
2 |
Runtime error |
72 ms |
28368 KB |
Execution killed with signal 6 |
3 |
Incorrect |
59 ms |
14288 KB |
Output isn't correct |
4 |
Runtime error |
7 ms |
10584 KB |
Execution killed with signal 6 |
5 |
Incorrect |
1 ms |
5468 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
5464 KB |
Output isn't correct |
7 |
Runtime error |
6 ms |
10912 KB |
Execution killed with signal 6 |
8 |
Runtime error |
6 ms |
10844 KB |
Execution killed with signal 6 |
9 |
Incorrect |
7 ms |
5724 KB |
Output isn't correct |
10 |
Runtime error |
22 ms |
17140 KB |
Execution killed with signal 6 |
11 |
Incorrect |
86 ms |
14272 KB |
Output isn't correct |
12 |
Incorrect |
50 ms |
14444 KB |
Output isn't correct |
13 |
Incorrect |
69 ms |
14288 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
10328 KB |
Output is correct |
2 |
Incorrect |
148 ms |
22248 KB |
Output isn't correct |
3 |
Incorrect |
59 ms |
18520 KB |
Output isn't correct |
4 |
Runtime error |
38 ms |
21536 KB |
Execution killed with signal 6 |
5 |
Runtime error |
23 ms |
21340 KB |
Execution killed with signal 6 |
6 |
Incorrect |
50 ms |
10836 KB |
Output isn't correct |
7 |
Incorrect |
52 ms |
10152 KB |
Output isn't correct |
8 |
Correct |
26 ms |
10328 KB |
Output is correct |
9 |
Incorrect |
110 ms |
22588 KB |
Output isn't correct |
10 |
Incorrect |
127 ms |
22288 KB |
Output isn't correct |
11 |
Incorrect |
115 ms |
22028 KB |
Output isn't correct |
12 |
Incorrect |
122 ms |
20508 KB |
Output isn't correct |
13 |
Correct |
85 ms |
24784 KB |
Output is correct |
14 |
Incorrect |
67 ms |
18376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
15072 KB |
Output isn't correct |
2 |
Incorrect |
169 ms |
20808 KB |
Output isn't correct |
3 |
Correct |
79 ms |
23688 KB |
Output is correct |
4 |
Incorrect |
89 ms |
20428 KB |
Output isn't correct |
5 |
Incorrect |
84 ms |
20064 KB |
Output isn't correct |
6 |
Incorrect |
94 ms |
20060 KB |
Output isn't correct |
7 |
Incorrect |
90 ms |
18640 KB |
Output isn't correct |
8 |
Correct |
84 ms |
23688 KB |
Output is correct |
9 |
Incorrect |
116 ms |
22736 KB |
Output isn't correct |
10 |
Incorrect |
128 ms |
22992 KB |
Output isn't correct |
11 |
Incorrect |
127 ms |
22252 KB |
Output isn't correct |
12 |
Incorrect |
121 ms |
20688 KB |
Output isn't correct |
13 |
Correct |
140 ms |
26728 KB |
Output is correct |
14 |
Incorrect |
109 ms |
18356 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
111 ms |
22740 KB |
Output isn't correct |
2 |
Incorrect |
120 ms |
20732 KB |
Output isn't correct |
3 |
Correct |
98 ms |
26456 KB |
Output is correct |
4 |
Incorrect |
116 ms |
22936 KB |
Output isn't correct |
5 |
Incorrect |
112 ms |
22248 KB |
Output isn't correct |
6 |
Incorrect |
109 ms |
22168 KB |
Output isn't correct |
7 |
Incorrect |
124 ms |
20572 KB |
Output isn't correct |
8 |
Correct |
81 ms |
26572 KB |
Output is correct |
9 |
Incorrect |
59 ms |
18384 KB |
Output isn't correct |