Submission #848307

#TimeUsernameProblemLanguageResultExecution timeMemory
848307math_rabbit_1028Beech Tree (IOI23_beechtree)C++17
58 / 100
2059 ms71068 KiB
#include "beechtree.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int n, m; vector<int> p, c; vector<int> adj[202020], res; int sz[202020]; void solve(int v) { sz[v] = 1; for (int i = 0; i < adj[v].size(); i++) { int u = adj[v][i]; solve(u); sz[v] += sz[u]; } priority_queue< pair<pii, int> > pq; vector<int> vec; pq.push({{sz[v], 0}, v}); while (!pq.empty()) { int now = pq.top().second; vec.push_back(now); pq.pop(); for (int i = 0; i < adj[now].size(); i++) { int u = adj[now][i]; pq.push({{sz[u], -vec.size()}, u}); } } map<int, int> cnt; for (int i = 1; i < sz[v]; i++) { int now = vec[i], par; if (cnt.find(c[now]) == cnt.end()) { par = vec[0]; cnt.insert({c[now], 1}); } else { par = vec[cnt[c[now]]]; cnt[c[now]]++; } if (par != p[now]) { res[v] = 0; return; } } } vector<int> beechtree(int N, int M, vector<int> P, vector<int> C) { n = N; m = M; p = P; c = C; for (int i = 1; i < n; i++) { adj[p[i]].push_back(i); } for (int i = 0; i < n; i++) res.push_back(1); solve(0); return res; }

Compilation message (stderr)

beechtree.cpp: In function 'void solve(int)':
beechtree.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i = 0; i < adj[v].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~
beechtree.cpp:27:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for (int i = 0; i < adj[now].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~
#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...