#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
int act[100005], rem[100005];
bool leaf[100005];
vector<int> pos;
void dfs(int v) {
for(auto u : adj[v]) {
dfs(u);
pos[v] = max(pos[v], pos[u]);
}
}
int solve(int N, int M, vector<int> F, vector<vector<int>> S) {
for(int l = 0; l < N; l++)
adj[l].clear(), act[l] = leaf[l] = 0;
for(int l = 1; l < N; l++)
adj[F[l]].push_back(l);
pos = vector<int> (N);
for(int l = 0; l < N - 1; l++)
pos[S[0][l]] = l;
dfs(0);
int res = 0;
int hi = -1;
for(int l = 0; l < N - 1; l++) {
hi = max(hi, pos[S[0][l]]);
if(hi == l) res++;
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3516 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3516 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3516 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Correct |
1 ms |
3420 KB |
Output is correct |
9 |
Correct |
1 ms |
3420 KB |
Output is correct |
10 |
Correct |
1 ms |
3420 KB |
Output is correct |
11 |
Correct |
1 ms |
3420 KB |
Output is correct |
12 |
Correct |
1 ms |
3524 KB |
Output is correct |
13 |
Correct |
1 ms |
3540 KB |
Output is correct |
14 |
Correct |
1 ms |
3420 KB |
Output is correct |
15 |
Correct |
1 ms |
3420 KB |
Output is correct |
16 |
Correct |
1 ms |
3672 KB |
Output is correct |
17 |
Correct |
1 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Incorrect |
2 ms |
3596 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3516 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
90 ms |
20908 KB |
Output is correct |
5 |
Correct |
117 ms |
20908 KB |
Output is correct |
6 |
Correct |
90 ms |
20916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3516 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Correct |
1 ms |
3420 KB |
Output is correct |
9 |
Correct |
1 ms |
3420 KB |
Output is correct |
10 |
Correct |
1 ms |
3420 KB |
Output is correct |
11 |
Correct |
1 ms |
3420 KB |
Output is correct |
12 |
Correct |
1 ms |
3524 KB |
Output is correct |
13 |
Correct |
1 ms |
3540 KB |
Output is correct |
14 |
Correct |
1 ms |
3420 KB |
Output is correct |
15 |
Correct |
1 ms |
3420 KB |
Output is correct |
16 |
Correct |
1 ms |
3672 KB |
Output is correct |
17 |
Correct |
1 ms |
3420 KB |
Output is correct |
18 |
Correct |
90 ms |
20908 KB |
Output is correct |
19 |
Correct |
117 ms |
20908 KB |
Output is correct |
20 |
Correct |
90 ms |
20916 KB |
Output is correct |
21 |
Correct |
106 ms |
15640 KB |
Output is correct |
22 |
Correct |
106 ms |
15812 KB |
Output is correct |
23 |
Correct |
112 ms |
16884 KB |
Output is correct |
24 |
Correct |
99 ms |
16884 KB |
Output is correct |
25 |
Correct |
108 ms |
15788 KB |
Output is correct |
26 |
Correct |
108 ms |
15636 KB |
Output is correct |
27 |
Correct |
111 ms |
16876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Incorrect |
2 ms |
3596 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3516 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |