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;
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;
}
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |