#include "september.h"
#include <vector>
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
std::vector<int> seen_count(N, 0);
std::vector<int> child_count(N, 0);
for (int i = 1; i < N; i++) {
child_count[F[i]]++;
}
int unresolved = 0;
int day_count = 0;
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < M; j++) {
int node = S[j][i];
seen_count[node]++;
if (seen_count[node] == 1) unresolved++;
if (seen_count[node] == M) {
unresolved--;
int curr = node;
while (curr != 0) {
int parent = F[curr];
child_count[parent]--;
if (child_count[parent] == 0 && (parent == 0 || seen_count[parent] == M)) {
curr = parent;
} else {
break;
}
}
}
}
if (unresolved == 0) {
day_count++;
}
}
return day_count;
}
| # | 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... |