이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "september.h"
#include <bits/stdc++.h>
using namespace std;
#define output_vector(v) for(auto &x : v){cout << x << ' ';}cout << '\n';
#define show(x) cerr << (#x) << " = " << (x) << '\n';
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
int ans = N;
vector<vector<int>> child(N);
for(int i=1; i<N; ++i) {
child[F[i]].push_back(i);
}
for(int i=0; i<M; ++i) {
int cnt = 0;
set<int> cur;
vector<set<int>> c(N);
for(int j=0; j<N; ++j) {
for(auto &k : child[j])
c[j].insert(k);
}
for(int j=0; j<N-1; ++j) {
int k = S[i][j];
cur.insert(k);
while(k > 0 && cur.count(k) && c[k].empty()) {
cur.erase(k);
c[F[k]].erase(k);
k = F[k];
}
cnt += (cur.empty());
}
ans = min(ans, cnt);
}
return ans;
}
// void taskcase() {
// int N, M;
// assert(2 == scanf("%d%d", &N, &M));
// std::vector<int> F(N);
// F[0] = -1;
// for (int i = 1; i < N; ++i)
// assert(1 == scanf("%d", &F[i]));
// std::vector<std::vector<int>> S(M, std::vector<int>(N - 1));
// for (int i = 0; i < M; ++i)
// for (int j = 0; j < N - 1; ++j)
// assert(1 == scanf("%d", &S[i][j]));
// printf("%d\n", solve(N, M, F, S));
// }
// int main() {
// int T;
// assert(1 == scanf("%d", &T));
// while(T--) taskcase();
// return 0;
// }
# | 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... |