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 output_vector(v) for(auto &x : v){cout << x << ' ';}cout << '\n';
#define show(x) cerr << (#x) << " = " << (x) << '\n';
#define sz(x) int(x.size())
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
int ans = 0;
vector<vector<int>> child(N);
for(int i=1; i<N; ++i) {
child[F[i]].push_back(i);
}
vector<vector<set<int>>> c(M, vector<set<int>>(N));
vector<set<int>> cur(M), track(M);
for(int j=0; j<N; ++j) {
for(auto &k : child[j]) {
for(int i=0; i<M; ++i) c[i][j].insert(k);
}
}
for(int j=0; j<N-1; ++j) {
for(int i=0; i<M; ++i) {
int k = S[i][j];
cur[i].insert(k);
track[i].insert(k);
while(k > 0 && cur[i].count(k) && c[i][k].empty()) {
cur[i].erase(k);
c[i][F[k]].erase(k);
k = F[k];
}
}
bool cnt = 0, same = true;
for(int i=0; i<M; ++i) {
cnt += sz(cur[i]);
}
for(int i=1; i<M; ++i) {
if(track[i] != track[0]) same = false;
}
if(cnt == 0 && same) {
++ans;
for(int i=0; i<M; ++i)
track[i].clear();
}
}
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... |