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>
#include "september.h"
#include <vector>
using namespace std;
int K,i,j,idx,child[100005],w[100005],mx[100005],x;
vector<int> v[100005],u;
bitset<100005> vis;
void dfs(int x){
u.push_back(x);
child[x]=1;
for(int i:v[x]){
dfs(i);
child[x]+=child[i];
}
}
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S){
K=0;
u.clear();
for(i=0;i<N;i++){
v[i].clear();
mx[i]=0;
}
vis.reset();
for(i=1;i<N;i++){
v[F[i]].push_back(i);
}
for(j=0;j<M;j++){
for(i=0;i<N-1;i++){
mx[S[j][i]]=max(mx[S[j][i]],i+1);
}
}
dfs(0);
for(i=0;i<N;i++) w[u[i]]=i;
idx=1;
i=0;
while(idx<N){
K++;
for(;i<idx;i++){
x=S[0][i];
for(j=w[x];j<w[x]+child[x];j++){
if(vis[u[j]]){
j+=child[u[j]];
j--;
continue;
}
vis[u[j]]=1;
idx=max(idx,mx[u[j]]);
}
}
idx++;
}
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... |