제출 #1334451

#제출 시각아이디문제언어결과실행 시간메모리
1334451x93bd09월 (APIO24_september)C++20
0 / 100
1 ms580 KiB
#include <bits/stdc++.h>
using namespace std;

int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
  vector<vector<int>> C(N);
  for (uint x = 1; x < N; x++)
    C[F[x]].push_back(x);

  set<uint> removed, toberemoved;

  function<void(uint)> dfs = [&](uint n) {
    for (uint c: C[n]) {
      if (toberemoved.count(n) || removed.count(n)) continue;
      toberemoved.insert(n);
      dfs(c);
    }
  };

  uint K = 0;
  uint badfllstate = 0;
  map<uint, uint> FLL;
  for (uint i = 0; i < N - 1; i++) {
    for (uint x = 0; x < M; x++) {
      if (!FLL[S[x][i]]) {
        badfllstate++;
        if (toberemoved.count(S[x][i]))
          toberemoved.erase(S[x][i]);
        removed.insert(S[x][i]);
        dfs(S[x][i]);
      }

      FLL[S[x][i]]++;
      if (FLL[S[x][i]] == M) badfllstate--;
    }

    if (!badfllstate && toberemoved.empty()) {
      K++;
    }
  }

  return K;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...