Submission #989616

#TimeUsernameProblemLanguageResultExecution timeMemory
989616bachhoangxuanSplit the Attractions (IOI19_split)C++17
40 / 100
66 ms29772 KiB
#include "split.h" #include<bits/stdc++.h> using namespace std; const int maxn = 2e5+5; #define pii pair<int,int> #define fi first #define se second vector<int> edge[maxn],tree[maxn]; int low[maxn],num[maxn],sz[maxn],T; bool del[maxn]; void pre_dfs(int u,int p){ sz[u]=1; low[u]=num[u]=++T; for(int v:edge[u]){ if(v==p) continue; if(!num[v]){ pre_dfs(v,u); sz[u]+=sz[v]; tree[u].push_back(v); low[u]=min(low[u],low[v]); //cout << "tree " << u << ' ' << v << '\n'; } else low[u]=min(low[u],num[v]); } } vector<int> find_split(int n, int A, int B, int C, vector<int> U, vector<int> V) { int m=(int)U.size(); vector<pii> S={{A,1},{B,2},{C,3}}; sort(S.begin(),S.end()); for(int i=0;i<m;i++){ edge[U[i]].push_back(V[i]); edge[V[i]].push_back(U[i]); } pre_dfs(0,0); int x=0; bool check=true; while(check){ check=false; for(int v:tree[x]) if(sz[v]>=S[0].fi){ x=v,check=true; break; } } vector<int> c(n,S[2].se); function<void(int,int,int)> color = [&](int u,int t,int a){ if(!S[t].fi || u==a) return; c[u]=S[t].se;S[t].fi--; for(int v:tree[u]) color(v,t,a); }; //cout << x << '\n'; int ss=sz[x]; for(int v:tree[x]){ if(low[v]<=num[x] && ss-sz[v]>=S[0].fi){ //cout << "del " << v << '\n'; del[v]=true; ss-=sz[v]; } } if(n-ss>=S[1].fi) swap(S[0],S[1]); if(n-ss>=S[0].fi){ color(0,0,x); S[1].fi--;c[x]=S[1].se; for(int v:tree[x]){ if(!del[v]) color(v,1,-1); else color(v,0,-1); } } else return vector<int>(n,0); return c; }
#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...