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;
const int N = 1e5+5;
vector<int> adj[N];
int pos[N], vis[N], r;
void dfs(int nd){
if(vis[nd])
return;
vis[nd] = 1;
r = max(r, pos[nd]);
for(auto i : adj[nd])
dfs(i);
}
int solve(int n, int m, vector<int> F, vector<vector<int>> S){
assert(m == 1);
for(int i = 0; i <= n; ++i)
adj[i].clear(), pos[i] = 0, vis[i] = 0;
for(int i = 1; i < n; ++i)
adj[F[i]].push_back(i);
for(int i = 0; i < n-1; ++i)
pos[S[0][i]] = i;
int l = 0, answer = 0;
r = 0;
while(r < n-1){
while(l <= r){
dfs(S[0][l]);
l++;
}
r++, answer++;
}
return answer;
}
# | 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... |