Submission #940057

#TimeUsernameProblemLanguageResultExecution timeMemory
940057Trisanu_DasBeech Tree (IOI23_beechtree)C++17
18 / 100
2037 ms20860 KiB
#include "beechtree.h" #include <bits/stdc++.h> using namespace std; typedef tuple<int, int, int> piii; int N, M; vector<int> adj[202020]; vector<int> P, C; int cnt[202020]; int idx[202020]; bool solve(int rt) { for (int i = 1; i <= M; i++) cnt[i] = 0; int id = 0; priority_queue<piii> pq; pq.emplace((int)adj[rt].size(), 0, rt); while (pq.size()) { int x = get<2>(pq.top()); pq.pop(); if (x != rt) { if (cnt[C[x]] != idx[P[x]]) return false; cnt[C[x]]++; } idx[x] = id++; for (int i : adj[x]) pq.emplace((int)adj[i].size(), -idx[x], i); } return true; } std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C) { ::N = N; ::M = M; ::P = P; ::C = C; vector<int> ans(N); for (int i = 1; i < N; i++) adj[P[i]].push_back(i); for (int i = 0; i < N; i++) ans[i] = solve(i); return ans; }
#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...