Submission #1039029

#TimeUsernameProblemLanguageResultExecution timeMemory
1039029ZicrusBeech Tree (IOI23_beechtree)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #include "beechtree.h" using namespace std; typedef long long ll; vector<int> beechtree(int n, int m, vector<int> p, vector<int> c) { vector<int> res(n, 1); vector<vector<ll>> adj(n); for (int i = 1; i < n; i++) { adj[p[i]].push_back(i); } vector<pair<ll, ll>> szId(n); for (int i = 0; i < n; i++) { szId[i] = {adj[i].size(), i}; } sort(szId.begin(), szId.end()); unordered_set<ll> used; if (szId.back().second != 0) res[0] = 0; for (auto &e : adj[0]) { if (used.count(c[e])) res[0] = 0; used.insert(c[e]); } for (int i = n-2; i >= 1; i--) { unordered_set<ll> nw; for (auto &e : adj[szId[i].second]) { if (!used.count(c[e])) res[0] = 0; if (nw.count(c[e])) res[szId[i].second] = res[0] = 0; nw.insert(c[e]); } used = nw; } return res; }
#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...