#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--){
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 |
5468 KB |
Output isn't correct |
2 |
Execution timed out |
1064 ms |
14036 KB |
Time limit exceeded |
3 |
Incorrect |
54 ms |
14452 KB |
Output isn't correct |
4 |
Execution timed out |
1037 ms |
5720 KB |
Time limit exceeded |
5 |
Incorrect |
1 ms |
5468 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
5468 KB |
Output isn't correct |
7 |
Execution timed out |
1070 ms |
5468 KB |
Time limit exceeded |
8 |
Execution timed out |
1052 ms |
5464 KB |
Time limit exceeded |
9 |
Incorrect |
5 ms |
5740 KB |
Output isn't correct |
10 |
Execution timed out |
1085 ms |
8724 KB |
Time limit exceeded |
11 |
Incorrect |
83 ms |
14284 KB |
Output isn't correct |
12 |
Incorrect |
54 ms |
14292 KB |
Output isn't correct |
13 |
Incorrect |
68 ms |
14164 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
10328 KB |
Output is correct |
2 |
Incorrect |
129 ms |
22120 KB |
Output isn't correct |
3 |
Incorrect |
62 ms |
18376 KB |
Output isn't correct |
4 |
Execution timed out |
1066 ms |
10844 KB |
Time limit exceeded |
5 |
Execution timed out |
1071 ms |
10588 KB |
Time limit exceeded |
6 |
Incorrect |
59 ms |
10836 KB |
Output isn't correct |
7 |
Incorrect |
53 ms |
10116 KB |
Output isn't correct |
8 |
Correct |
28 ms |
10332 KB |
Output is correct |
9 |
Incorrect |
116 ms |
22436 KB |
Output isn't correct |
10 |
Incorrect |
120 ms |
22224 KB |
Output isn't correct |
11 |
Incorrect |
115 ms |
21996 KB |
Output isn't correct |
12 |
Incorrect |
116 ms |
20424 KB |
Output isn't correct |
13 |
Correct |
88 ms |
24840 KB |
Output is correct |
14 |
Incorrect |
60 ms |
18376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
15060 KB |
Output isn't correct |
2 |
Incorrect |
136 ms |
20688 KB |
Output isn't correct |
3 |
Correct |
81 ms |
23504 KB |
Output is correct |
4 |
Incorrect |
77 ms |
20404 KB |
Output isn't correct |
5 |
Incorrect |
74 ms |
19920 KB |
Output isn't correct |
6 |
Incorrect |
80 ms |
19924 KB |
Output isn't correct |
7 |
Incorrect |
80 ms |
18884 KB |
Output isn't correct |
8 |
Correct |
83 ms |
23612 KB |
Output is correct |
9 |
Incorrect |
111 ms |
22704 KB |
Output isn't correct |
10 |
Incorrect |
145 ms |
22268 KB |
Output isn't correct |
11 |
Incorrect |
132 ms |
22196 KB |
Output isn't correct |
12 |
Incorrect |
140 ms |
20980 KB |
Output isn't correct |
13 |
Correct |
129 ms |
26600 KB |
Output is correct |
14 |
Incorrect |
95 ms |
18400 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
111 ms |
22736 KB |
Output isn't correct |
2 |
Incorrect |
134 ms |
21068 KB |
Output isn't correct |
3 |
Correct |
84 ms |
26596 KB |
Output is correct |
4 |
Incorrect |
110 ms |
22740 KB |
Output isn't correct |
5 |
Incorrect |
112 ms |
22308 KB |
Output isn't correct |
6 |
Incorrect |
107 ms |
22416 KB |
Output isn't correct |
7 |
Incorrect |
114 ms |
20684 KB |
Output isn't correct |
8 |
Correct |
86 ms |
26568 KB |
Output is correct |
9 |
Incorrect |
60 ms |
18252 KB |
Output isn't correct |