이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |