Submission #413038

#TimeUsernameProblemLanguageResultExecution timeMemory
413038ismoilovSplit the Attractions (IOI19_split)C++14
24 / 100
2069 ms24980 KiB
#include "split.h" #include<bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //#define int ll #define ve vector #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++) #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++) #define fv(a, c) for(int (a) = (1); (a) <= (c); (a)++) #define fz(a, c) for(int (a) = (0); (a) < (c); (a)++) #define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--) #define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--) #define pb push_back #define in insert #define ss second #define ff first #define vi vector <int> #define fa(a, v) for(auto (a) : (v)) #define mnel(a) *min_element(all(a)) #define mxel(a) *max_element(all(a)) #define si set<int> #define sov(a) sort(all((a))) ve<vi> G, C; vi num, siz, low; int n, x; pii X, Y, Z; bool found = 0, sol = 0; tuple<int, int, int> top ,bottom; vector <bool> B; void dfs (int u, int p){ siz[u] = 1; x ++; num[u] = x; low[u] = x; bool ok = 1; fa(v, G[u]){ if(num[v] == 0){ dfs(v, u); siz[u] += siz[v]; low[u] = min(low[v], low[u]); if(siz[v] >= X.ff) ok = 0; C[u].pb(v); } else if(v != p) low[u] = min(low[u], num[v]); } if(siz[u] < X.ff) ok = 0; if(ok && !found){ // cout << "found: " << u << " " << p << "\n"; found = 1; int cur = siz[u]; fa(v, C[u]){ if(low[v] < num[u]){ if(cur - siz[v] >= X.ff){ B[v] = 1; cur -= siz[v]; } } } int opt = n - cur; if(opt >= Y.ff){ sol = 1; top = {Y.ff, Y.ss, p}; bottom = {X.ff, X.ss, u}; } else if(opt >= X.ff){ sol = 1; top = {X.ff, X.ss, p}; bottom = {Y.ff, Y.ss, u}; } } } vector<int> find_split(int nn, int a, int b, int c, vector<int> p, vector<int> q) { vi ans(n); int m = p.size(); n = nn; G = ve<vi> (n); C = ve<vi> (n); num = vi (n); siz = vi (n); low = vi (n); B = ve<bool> (n); queue <int> Q; fp(i,0,m){ G[p[i]].pb(q[i]); G[q[i]].pb(p[i]); } ve<pii> A = {{a, 1}, {b, 2}, {c, 3}}; sort(all(A)); X = A[0], Y = A[1], Z = A[2]; dfs(0, -1); fp(i,0,n) // cout << i << " " << siz[i] << "\n"; if(sol){ ans = vi (n, Z.ss); int sz, d, s; tie(sz, d, s) = bottom; ans[s] = d; sz --; Q.push(s); while(Q.size()){ int u = Q.front(); Q.pop(); fa(v, C[u]){ if(!B[v]){ if(sz > 0){ ans[v] = d; Q.push(v); sz --; } } } } tie(sz, d, s) = top; ans[s] = d; sz--; Q.push(s); // cout << "top" << " "; while(Q.size()){ int u = Q.front(); Q.pop(); fa(v, G[u]){ // cout << v << " " << ans[v] << "\n"; if(ans[v] == Z.ss){ if(sz > 0){ sz--; ans[v] = d; Q.push(v); } } } } } else ans = vi (n, 0); return ans; }

Compilation message (stderr)

split.cpp: In function 'void dfs(int, int)':
split.cpp:27:27: warning: unnecessary parentheses in declaration of 'v' [-Wparentheses]
   27 | #define fa(a, v) for(auto (a) : (v))
      |                           ^
split.cpp:48:5: note: in expansion of macro 'fa'
   48 |     fa(v, G[u]){
      |     ^~
split.cpp:27:27: warning: unnecessary parentheses in declaration of 'v' [-Wparentheses]
   27 | #define fa(a, v) for(auto (a) : (v))
      |                           ^
split.cpp:68:9: note: in expansion of macro 'fa'
   68 |         fa(v, C[u]){
      |         ^~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:16:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
split.cpp:105:5: note: in expansion of macro 'fp'
  105 |     fp(i,0,m){
      |     ^~
split.cpp:16:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
split.cpp:115:5: note: in expansion of macro 'fp'
  115 |     fp(i,0,n)
      |     ^~
split.cpp:27:27: warning: unnecessary parentheses in declaration of 'v' [-Wparentheses]
   27 | #define fa(a, v) for(auto (a) : (v))
      |                           ^
split.cpp:128:13: note: in expansion of macro 'fa'
  128 |             fa(v, C[u]){
      |             ^~
split.cpp:27:27: warning: unnecessary parentheses in declaration of 'v' [-Wparentheses]
   27 | #define fa(a, v) for(auto (a) : (v))
      |                           ^
split.cpp:147:13: note: in expansion of macro 'fa'
  147 |             fa(v, G[u]){
      |             ^~
#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...