Submission #584951

#TimeUsernameProblemLanguageResultExecution timeMemory
5849518e7Split the Attractions (IOI19_split)C++17
100 / 100
125 ms30120 KiB
//Challenge: Accepted #include <bits/stdc++.h> #include "split.h" #pragma GCC optimize("Ofast") using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 200005 #define mod 1000000007 #define pii pair<int, int> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); using namespace std; vector<int> adj[maxn], g[maxn]; //g is spanning tree int C; int low[maxn], ti[maxn], siz[maxn], pa[maxn]; void dfs(int n, int par) { pa[n] = par; ti[n] = low[n] = C; C++; siz[n] = 1; for (int v:adj[n]) { if (!ti[v]) { dfs(v, n); siz[n] += siz[v]; low[n] = min(low[n], low[v]); g[v].push_back(n); g[n].push_back(v); } else { low[n] = min(low[n], ti[v]); } } } void getnode(int n, int par, vector<int> &vec, int s){ vec.push_back(n); if (vec.size() >= s) return; for (int v:g[n]) { if (v != par) { getnode(v, n, vec, s); if (vec.size() >= s) return; } } } bool vis[maxn]; void getset(int n, vector<int> &vec, vector<int> &mark, int s) { vec.push_back(n); if (vec.size() >= s) return; vis[n] = 1; for (int v:adj[n]) { if (!vis[v] && mark[v]) { getset(v, vec, mark, s); if (vec.size() >= s) return; } } } vector<int> find_split(int n, int a, int b, int c, vector<int> P, vector<int> Q) { C = 1; vector<int> ret(n, 0); int m = P.size(); for (int i = 0;i < m;i++) { adj[P[i]].push_back(Q[i]); adj[Q[i]].push_back(P[i]); } dfs(0, 0); pii ord[3] = {{a, 1}, {b, 2}, {c, 3}}; sort(ord, ord + 3); for (int i = 0;i < 3;i++) debug(ord[i].ff, ord[i].ss); int A = ord[0].ff, B = ord[1].ff; int p = 0; for (int i = 0;i < n;i++) { if (A <= siz[i] && siz[i] <= n - A) { for (int j = 0;j < n;j++) ret[j] = ord[2].ss; vector<int> va, vb; if (siz[i] * 2 <= n) { getnode(i, pa[i], va, A); getnode(pa[i], i, vb, B); } else { getnode(pa[i], i, va, A); getnode(i, pa[i], vb, B); } for (int j:va) ret[j] = ord[0].ss; for (int j:vb) ret[j] = ord[1].ss; return ret; } if (siz[i] > n - A) { bool good = 1; for (int v:g[i]) { if (v != pa[i] && siz[v] >= A) { good = 0; break; } } if (good) p = i; } } if (p != 0) { int s = n - siz[p]; vector<int> vec; getnode(pa[p], p, vec, s); for (int v:g[p]) { if (vec.size() >= A) break; if (v != pa[p] && low[v] < ti[p]) { getnode(v, p, vec, vec.size() + siz[v]); } } vector<int> se(n, 0); for (int i:vec) se[i] = 1; //pary(se.begin(), se.end()); if (vec.size() < A) return ret; for (int j = 0;j < n;j++) ret[j] = ord[2].ss; vector<int> va, vb; if (vec.size() >= B) { getset(pa[p], vb, se, B); for (int i = 0;i < n;i++) se[i] ^= 1; getset(p, va, se, A); } else { getset(pa[p], va, se, A); for (int i = 0;i < n;i++) se[i] ^= 1; getset(p, vb, se, B); } pary(va.begin(), va.end()); pary(vb.begin(), vb.end()); for (int j:va) ret[j] = ord[0].ss; for (int j:vb) ret[j] = ord[1].ss; } return ret; } /* 7 7 2 2 3 0 1 1 2 1 3 1 4 1 5 1 6 0 2 */

Compilation message (stderr)

split.cpp: In function 'void getnode(int, int, std::vector<int>&, int)':
split.cpp:48:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |  if (vec.size() >= s) return;
      |      ~~~~~~~~~~~^~~~
split.cpp:52:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |    if (vec.size() >= s) return;
      |        ~~~~~~~~~~~^~~~
split.cpp: In function 'void getset(int, std::vector<int>&, std::vector<int>&, int)':
split.cpp:60:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |  if (vec.size() >= s) return;
      |      ~~~~~~~~~~~^~~~
split.cpp:65:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |    if (vec.size() >= s) return;
      |        ~~~~~~~~~~~^~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
split.cpp:81:28: note: in expansion of macro 'debug'
   81 |  for (int i = 0;i < 3;i++) debug(ord[i].ff, ord[i].ss);
      |                            ^~~~~
split.cpp:116:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  116 |    if (vec.size() >= A) break;
      |        ~~~~~~~~~~~^~~~
split.cpp:125:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  125 |   if (vec.size() < A) return ret;
      |       ~~~~~~~~~~~^~~
split.cpp:128:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  128 |   if (vec.size() >= B) {
      |       ~~~~~~~~~~~^~~~
split.cpp:15:19: warning: statement has no effect [-Wunused-value]
   15 | #define pary(...) 0
      |                   ^
split.cpp:138:3: note: in expansion of macro 'pary'
  138 |   pary(va.begin(), va.end());
      |   ^~~~
split.cpp:15:19: warning: statement has no effect [-Wunused-value]
   15 | #define pary(...) 0
      |                   ^
split.cpp:139:3: note: in expansion of macro 'pary'
  139 |   pary(vb.begin(), vb.end());
      |   ^~~~
#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...