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 S[j][i] S[0][i]
// two pointers?
int solve(int N, int M, std::vector<int> P, std::vector<std::vector<int>> S) {
vi CHILDREN(N);
vector<bool> LEAVES(N);
for(int i=1; i<N; ++i) {
CHILDREN[P[i]]++;
}
rep(N){
if (CHILDREN[i]==0) LEAVES[i] = true;
}
int res =INT_MAX;
for (int j =0; j < M; ++j) {
int tempres = 0;
int BCNTR = 0;
vi C = CHILDREN;
vector<bool> L=LEAVES;
vector<bool> B(N,false);
rep(N-1) {
if (L[S[j][i]]) {
C[P[S[j][i]]]--;
//cout << "IS LEAF "<<S[j][i] << endl;
if (C[P[S[j][i]]] == 0 && B[P[S[j][i]]]== true) {
B[P[S[j][i]]] = false;
BCNTR--;
//cout << "RMV BRANCH " << P[S[j][i]] << endl;
}
else if (C[P[S[j][i]]]==0 && B[P[S[j][i]]]==false) {
L[P[S[j][i]]] = true;
//cout << "ADD LEAF " << P[S[j][i]]<< endl;
}
} else {
B[S[j][i]] = true;
BCNTR++;
//cout << "ADD BRANCH " << S[j][i]<<endl;
}
if(BCNTR==0) {
tempres++;
//cout << "RES++" << endl;
}
}
res = min(tempres, res);
}
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... |