Submission #986609

#TimeUsernameProblemLanguageResultExecution timeMemory
986609mariaclaraSplit the Attractions (IOI19_split)C++17
0 / 100
42 ms8632 KiB
#include "split.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define mk make_pair #define pb push_back #define fr first #define sc second int A, B, no = -1, pai; vector<int> sub, vis; vector<vector<int>> edges; void dfs(int x, int anc) { sub[x] = 1; vis[x] = 1; for(int viz : edges[x]) if(!vis[viz]) dfs(viz, x), sub[x] += sub[viz]; if(sub[x] >= A and sz(sub)-sub[x] >= B or sub[x] >= B and sz(sub)-sub[x] >= A) no = x, pai = anc; } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { edges.resize(n); for(int i = 0; i < sz(p); i++) edges[p[i]].pb(q[i]), edges[q[i]].pb(p[i]); if(a == 100) { queue<int> fila; vector<int> ans(n); fila.push(0); int cnt = 0; while(!fila.empty()) { int x = fila.front(); fila.pop(); if(ans[x]) continue; ans[x] = 2; cnt++; if(cnt == b) break; for(int viz : edges[x]) if(!ans[viz]) fila.push(viz); } for(int i = 0; i < n; i++) if(a and ans[i] == 0) ans[i] = 1, a = 0; else if(ans[i] == 0) ans[i] = 3; return ans; } else{ sub.resize(n); vis.resize(n); A = min({a,b,c}); B = min({max(a,b), max(b,c), max(c,a)}); dfs(0, 0); vector<int> ans(n); if(no == -1) return ans; int type = 1; if(n - sub[no] < B) type = 2; for(int i = 0; i < sz(edges[no]); i++) { if(edges[no][i] == pai) { edges[no].erase(edges[no].begin()+i); break; } } queue<int> fila; fila.push(no); int cnt = 0; while(!fila.empty()) { int x = fila.front(); fila.pop(); if(ans[x]) continue; ans[x] = type; cnt++; if(cnt == A) break; for(int viz : edges[x]) if(!ans[viz]) fila.push(viz); } while(!fila.empty()) fila.pop(); fila.push(pai); cnt = 0; while(!fila.empty()) { int x = fila.front(); fila.pop(); if(ans[x]) continue; ans[x] = 3-type; cnt++; if(cnt == B) break; for(int viz : edges[x]) if(!ans[viz]) fila.push(viz); } for(int i = 0; i < n; i++) { if(ans[i] == 1) { if(a > A and b == A) ans[i] = 2; else if(a > A) ans[i] = 3; } else if(ans[i] == 2) { if(a > A and a == B) ans[i] = 1; else if(b > B or (b == A and a > A)) ans[i] = 3; } else { if(a > B) ans[i] = 1; else if(b > B or (b > c and b >= a)) ans[i] = 2; else ans[i] = 3; } } return ans; } }

Compilation message (stderr)

split.cpp: In function 'void dfs(int, int)':
split.cpp:26:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   26 |  if(sub[x] >= A and sz(sub)-sub[x] >= B
#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...