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;
vector<vector<int>> adj;
vector<bool> vis;
int Time = -1;
void dfs(int x)
{
if(vis[x])
return ;
vis[x] = 1;
Time++;
for(auto u : adj[x])
{
dfs(u);
}
}
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S)
{
adj.clear();
adj.assign(N , {});
vis.assign(N , 0);
Time = -1;
for(int i = 1 ; i <= N - 1 ; i++)
{
adj[F[i]].push_back(i);
}
int d = 0;
vector<int> occ(N);
set<int> diff;
for(int i = 0 ; i < N - 1 ; i++)
{
for(int j = 0 ; j < M ; j++)
{
dfs(S[j][i]);
if(occ[S[j][i]] == 0)
diff.insert(S[j][i]);
if(occ[S[j][i]] + 1 == M)
{
diff.erase(S[j][i]);
}
occ[S[j][i]]++;
}
if(diff.empty() && Time == 0)
{
d++;
}
Time--;
}
return d;
}
# | 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... |