이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
int act[100005];
bool leaf[100005];
int solve(int N, int M, vector<int> F, vector<vector<int>> S) {
for(int l = 0; l < N; l++)
adj[l].clear(), act[l] = leaf[l] = 0;
for(int l = 1; l < N; l++)
adj[F[l]].push_back(l);
for(int l = 0; l < N; l++) {
if(adj[l].size() > 0) act[l] = (int)adj[l].size();
else leaf[l] = 1;
}
int res = 0, cur = 0;
for(int l = 0; l < N - 1; l++) {
int U = S[0][l];
if(leaf[U]) {
leaf[F[U]] = 1;
if(act[F[U]]) cur--, act[F[U]]--;
if(cur == 0) ++res;
}
else cur++;
}
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... |