Submission #986608

#TimeUsernameProblemLanguageResultExecution timeMemory
986608mariaclaraSplit the Attractions (IOI19_split)C++17
18 / 100
66 ms15988 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) 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; 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] = 1; 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] = 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(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; } } /* 5 5 2 2 1 1 4 4 0 0 3 3 2 2 1 */
#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...