#include <bits/stdc++.h>
#include "september.h"
using namespace std;
int solve(int N, int M, vector<int> F, vector<vector<int> > S) {
vector<vector<int> > adjList;
adjList.resize(N);
for (int i = 1; i < N; i++) {
adjList[F[i]].push_back(i);
}
unordered_set<int> beenBanished;
vector<unordered_map<int, int> > actualIndices(M);
for(int i = 0; i < M; i++) {
for (int j = 0; j < N - 1; j++) {
actualIndices[i][S[i][j]] = j;
}
}
unordered_map<int, int> actualIndex;
for (int i = 1; i < N; i++) {
actualIndex[i] = 0;
for (int j = 0; j < M; j++) {
actualIndex[i] = max(actualIndices[j][i], actualIndex[i]);
}
}
int banishmentIndex = 0;
int maxK = 1;
for (int i = 0; i < N - 1; i++) {
if (banishmentIndex < i) {
maxK++;
}
queue<int> bfsQueue;
for (int j = 0; j < M; j++) {
bfsQueue.push(S[j][i]);
}
while (!bfsQueue.empty()) {
int currentIndex = bfsQueue.front();
bfsQueue.pop();
if (beenBanished.find(currentIndex) != beenBanished.end()) {
continue;
}
beenBanished.insert(currentIndex);
banishmentIndex = max(banishmentIndex, actualIndex[currentIndex]);
for (int v: adjList[currentIndex]) {
bfsQueue.push(v);
}
}
}
return maxK;
}
# | 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... |