Submission #1123425

#TimeUsernameProblemLanguageResultExecution timeMemory
1123425LucaLucaMSeptember (APIO24_september)C++20
59 / 100
222 ms10432 KiB
#include "september.h"

#include <vector>
#include <algorithm>
#include <iostream>

#define debug(x) #x << " = " << x << '\n'

int solve(int n, int m, std::vector<int> parent, std::vector<std::vector<int>> s) {
	std::vector<bool> ok(n - 1, true);
  std::vector<std::vector<int>> g(n);
  for (int i = 1; i < n; i++) {
    g[parent[i]].push_back(i);
    g[i].push_back(parent[i]);
  }
  for (const auto &a : s) {
    std::vector<bool> alive(n, true);
    int cur = n - 1;
    for (int i = 0; i < n - 1; i++) {
      // daca sterg nodurile 0..i atunci cate noduri u am a.i. si u si parent[u] sunt vii?
      int u = a[i];
      // std::cout << debug(u) << ' ' << debug(parent[u]);
      for (const auto &v : g[u]) {
        if (alive[v]) {
          cur--;
        }
      }
      alive[u] = false;
      if (cur != n - 2 - i) {
        ok[i] = false;
      }
    }
  }

  return std::count(ok.begin(), ok.end(), true);
}
#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...