Submission #297519

#TimeUsernameProblemLanguageResultExecution timeMemory
297519shayan_pSplit the Attractions (IOI19_split)C++17
11 / 100
143 ms14076 KiB
#include<bits/stdc++.h> #include "split.h" #define F first #define S second #define PB push_back #define sz(s) (int(s.size())) #define bit(n, k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 1e5 + 10; vector<int> v[maxn]; int pr[maxn], SZ[maxn]; bool mark[maxn]; int col[maxn]; void dfs(int u){ SZ[u] = 1; mark[u] = 1; for(int y : v[u]){ if(!mark[y]) pr[y] = u, dfs(y), SZ[u]+= SZ[y]; } } int color(int u, int cnt, int c){ assert(cnt); cnt--; col[u] = c; for(int y : v[u]){ if(mark[y] == mark[u] && col[y] != c && cnt) cnt = color(y, cnt, c); } return cnt; } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q){ vector<pii> SZS; SZS.PB({a, 1}); SZS.PB({b, 2}); SZS.PB({c, 3}); sort(SZS.begin(), SZS.end()); int A = SZS[0].F; assert(A == 1); auto mkay = [&](int chert){ int cnt = 0, ZR = -1, ON = -1; for(int i = 0; i < n; i++){ if(mark[i] == 0) ZR = i; else ON = i; cnt+= mark[i]; } assert(cnt == chert); assert(A <= cnt && cnt <= n-A); if(cnt > SZS[1].F) swap(ZR, ON); color(ON, SZS[0].F, SZS[0].S); color(ZR, SZS[1].F, SZS[1].S); vector<int> ans; for(int i = 0; i < n; i++){ if(col[i] == 0) col[i] = SZS[2].S; ans.PB(col[i]); } return ans; }; for(int i = 0; i < sz(p); i++){ v[p[i]].PB(q[i]); v[q[i]].PB(p[i]); } dfs(0); int r = 0; for(int i = 0; i < n; i++) if(SZ[i] == 1) r = i; memset(mark, 0, sizeof mark); mark[r] = 1; return mkay(1); /* dfs(0); for(int u = 0; u < n; u++){ if(A <= SZ[u] && SZ[u] <= n-A){ for(int i = 0; i < n; i++) v[i].clear(); for(int i = 1; i < n; i++) v[i].PB(pr[i]), v[pr[i]].PB(i); memset(mark, 0, sizeof mark); mark[pr[u]] = 1; dfs(u); mark[pr[u]] = 0; return mkay(SZ[u]); } } */ vector<int> ans(n); return ans; }
#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...