# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879419 | andrei_boaca | Split the Attractions (IOI19_split) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "split.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("fast-math")
//#pragma GCC optimize ("unroll-loops")
using namespace std;
typedef pair<int,int> pii;
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
int n,m;
int take[5],ord[5];
vector<int> sol;
bool byval(int a,int b)
{
return take[a]<take[b];
}
vector<int> kids[100005],edges[100005];
vector<int> dsu[100005];
int comp[100005];
vector<pii> g;
vector<int> linie;
int par[100005];
bool use[100005];
vector<int> nodes;
int nr[100005];
int niv[100005],nivmin[100005];
int part[100005];
void dfs(int nod)
{
nr[nod]=1;
use[nod]=1;
nivmin[nod]=niv[nod];
for(int i:edges[nod])
{
if(i==par[nod])
continue;
if(!use[i])
{
niv[i]=niv[nod]+1;
dfs(i);
kids[nod].push_back(i);
nr[nod]+=nr[i];
nivmin[nod]=min(nivmin[nod],nivmin[i]);
}
else
nivmin[nod]=min(nivmin[nod],niv[i]);
}
}
vector<int> find_split(int N, int A, int B, int C, vector<int> p, vector<int> q)
{
n=N;
take[1]=A;
take[2]=B;
take[3]=C;
ord[1]=1;
ord[2]=2;
ord[3]=3;
sort(ord+1,ord+4,byval);
sol.resize(n);
m=p.size();
for(int i=0;i<n;i++)
{
par[i]=-1;
comp[i]=i+1;
dsu[i+1].push_back(i);
}
for(int i=0;i<p.size();i++)
{
int a,b;
a=p[i];
b=q[i];
edges[a].push_back(b);
edges[b].push_back(a);
}
niv[0]=1;
dfs(0);
for(int v=0;v<n;v++)
if(valid(v))
{
vector<int> rebeli;
int lg1=nr[v],lg2=n-nr[v];
for(int i=0;i<kids[v].size()&&!good(lg1,lg2);i++)
{
int u=kids[v][i];
if(nivmin[u]<nivmin[v]&&lg1-nr[u]>=take[ord[1]])
{
lg1-=nr[u];
rebeli.push_back(u);
lg2+=nr[u];
}
}
if(good(lg1,lg2))
{
part[v]=1;
for(int i:rebeli)
put(i,2);
if(par[v]!=-1)
put(par[v],2);
put(v,1);
}
}
}