이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
const int MN=1e6+5;
vector<int>v[MN];
bool vis[MN];
int par[MN];
int pos[5][MN];
int mx=-1;
void dfs(int a, int j){
vis[a]=1;
mx=max(mx,pos[j][a]);
for(auto b:v[a]){
if(vis[b]==1)continue;
dfs(b,j);
}
}
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
mx=0;
for(int i=0;i<N;i++){
v[i].clear();
vis[i]=0;
}
for(int i=1;i<N;i++){
par[i]=F[i];
v[F[i]].pb(i);
}
int k=0;
for(int i=0;i<N-1;i++){
for(int j=0;j<M;j++){
pos[j][S[0][i]]=i;
}
}
int i=0;
while(i<N-1){
while(i<=mx){
for(int j=0;j<M;j++){
int a=S[j][i];
if(vis[a]==0){
dfs(a,j);
}
}
i++;
}
mx++;
k++;
}
return k;
}
# | 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... |