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