제출 #1123426

#제출 시각아이디문제언어결과실행 시간메모리
1123426LucaLucaM9월 (APIO24_september)C++20
100 / 100
235 ms11456 KiB
#include "september.h" #include <vector> #include <algorithm> #include <iostream> #include <random> std::mt19937 rng(123); #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]); } std::vector<int> rnd(n); for (int i = 0; i < n; i++) { rnd[i] = rng(); } std::vector<int> hsh(n, -1); for (const auto &a : s) { std::vector<bool> alive(n, true); int cur = n - 1; int me = 0; 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]; me ^= rnd[u]; if (hsh[i] == -1) { hsh[i] = me; } else { if (hsh[i] != me) { ok[i] = false; } } // 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...