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 "september.h"
#include<bits/stdc++.h>
using namespace std;
int rem=0;
struct tree{
vector<int>adj[100005];
int vis[5][100005];
void dfs_add(int id,int u,int p=-1){
if(vis[id][u])return;
vis[id][u]=1;
rem++;
for(auto v:adj[u])dfs_add(id,v,u);
}
void remove(int u){
rem--;
}
void clear(int n,int m){
for(int i=0;i<=n;i++)adj[i].clear();
for(int i=0;i<m;i++)for(int j=0;j<n;j++)vis[i][j]=0;
}
}tr;
int solve(int N, int M, vector<int> F, vector<vector<int>> S) {
rem=0;
for(int i=0;i<M;i++)tr.clear(N,M);
for(int j=1;j<N;j++){
tr.adj[F[j]].push_back(j);
}
int ans=0;
for(int i=0;i<N-1;i++){
for(int j=0;j<M;j++){
//cerr<<S[j][i]<<"\n";
tr.dfs_add(j,S[j][i]);
//cerr<<"work\n";
tr.remove(S[j][i]);
}
if(rem==0)ans++;
//cerr<<"rem:"<<rem<<"\n";
}
return ans;
}
# | 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... |