Submission #824690

#TimeUsernameProblemLanguageResultExecution timeMemory
824690caganyanmazSplit the Attractions (IOI19_split)C++17
22 / 100
414 ms1048576 KiB
#include <bits/stdc++.h> #define pb push_back #include "split.h" using namespace std; constexpr static int MXN = 1e5; vector<int> g[MXN]; int subsize[MXN], n; vector<int> res; array<array<int, 2>, 3> arr; array<int, 3> counter; void dfs2(int node, int parent, int val) { if (counter[val] == arr[val][0]) return; counter[val]++; res[node] = arr[val][1]; for (int c : g[node]) if (c != parent) dfs2(c, node, val); } bool dfs1(int node, int parent) { subsize[node] = 1; for (int c : g[node]) { if (c != parent) { bool out = dfs1(c, node); if (out) return true; subsize[node] += subsize[c]; } } if (subsize[node] >= arr[0][0] && n - subsize[node] >= arr[1][0]) { dfs2(node, parent, 0); dfs2(parent, node, 1); return true; } else if (subsize[node] >= arr[1][0] && n - subsize[node] >= arr[0][0]) { dfs2(node, parent, 1); dfs2(parent, node, 0); return true; } return false; } vector<int> find_split(int _n, int a, int b, int c, vector<int> p, vector<int> q) { n = _n; res = vector<int>(n, 0); for (int i = 0; i < p.size(); i++) { g[p[i]].pb(q[i]); g[q[i]].pb(p[i]); } arr[0] = {a, 1}; arr[1] = {b, 2}; arr[2] = {c, 3}; sort(arr.begin(), arr.end()); if (dfs1(0, -1)) for (int i = 0; i < n; i++) if (!res[i]) res[i] = arr[2][1]; return res; }

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for (int i = 0; i < p.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...