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;
#define endl '\n'
#define rep(a) for(int i=0;i<a;++i)
#define ll long long
#define vi vector<int>
#define node S[j][i]
int solve(int N, int M, std::vector<int> P, std::vector<std::vector<int>> S) {
vi CHILDREN(N);
vi LEAVES(N);
for(int i=1; i<N; ++i) {
CHILDREN[P[i]]++;
}
rep(N){
if (CHILDREN[i]==0) LEAVES[i] = true;
}
int res = 0;
vector<vi> C(M, CHILDREN);
vector<vi> L(M, LEAVES);
vector<vi> B(M, vi(N));
int numBranches = 0;
rep(N-1) {
for(int j = 0; j < M; ++j) {
if (L[j][node]) {
C[j][P[node]]--;
if (C[j][P[node]] == 0 && B[j][P[node]] == true) {
B[j][P[node]] = false;
numBranches--;
} else if (C[j][P[node]] == 0 && B[j][P[node]] == false) {
L[j][P[node]] = true;
}
}
else {
B[j][node] = true;
numBranches++;
}
}
if (numBranches == 0) res += 1;
}
return res;
}
# | 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... |