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<bits/stdc++.h>
using namespace std;
typedef int ll;
#define x first
#define y second
vector<ll> cad[100005];
vector<ll> sts,sol;
ll aux=0;pair<ll,ll> st={1e9,1e9};
ll dfs(ll node){
if(sts[node]!=0) return 0;
sts[node]=1;
for(auto i:cad[node])
sts[node]+=dfs(i);
if(sts[node]>=aux)
st=min(st,{sts[node],node});
return sts[node];
}
void fillst(ll node, ll c, ll cnt)
{
sol[node]=c;cnt--;
queue<ll>q;q.push(node);
while(!q.empty())
{
for(auto i:cad[q.front()])
{
if(sts[i]<sts[q.front()]&&sol[i]==0&&cnt>0)
{
sol[i]=c;
cnt--;
q.push(i);
}
}
q.pop();
}
}
void fill2(ll n, pair<ll,ll> a, pair<ll,ll> b)
{
for(int i=0; i<n; i++)
{
if(sol[i]==0||sol[i]==5)
{
ll cnt=0;
sol[i]=5;
queue<ll>q;q.push(i);
while(!q.empty())
{
for(auto i:cad[q.front()])
{
if(sol[i]==0)
{
sol[i]=5;
cnt++;
q.push(i);
}
}
q.pop();
}
if(cnt>=a.x&&a.x!=0)
{
sol[i]=a.y;a.x--;
queue<ll>q;q.push(i);
while(!q.empty())
{
for(auto i:cad[q.front()])
{
if(sol[i]==5&&a.x>0)
{
sol[i]=a.y;
a.x--;
q.push(i);
}
}
q.pop();
}
}
else
{
sol[i]=b.y;b.x--;
queue<ll>q;q.push(i);
while(!q.empty())
{
for(auto i:cad[q.front()])
{
if(sol[i]==5&&b.x>0)
{
sol[i]=b.y;
b.x--;
q.push(i);
}
}
q.pop();
}
}
}
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
sts.assign(n,0);sol.assign(n,0);
pair<ll,ll> temp[]={{a,1},{b,2},{c,3}}; sort(temp,temp+3);
for(int i=0; i<p.size(); i++)
{
cad[p[i]].push_back(q[i]);
cad[q[i]].push_back(p[i]);
}
aux=temp[0].x;dfs(0);
if(n-st.x<temp[0].x) return sol;
if(st.x>n-st.x) swap(temp[0],temp[1]);
fillst(st.y,temp[0].y,temp[0].x);
fill2(n, temp[1],temp[2]);
return sol;
}
Compilation message (stderr)
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:100:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for(int i=0; i<p.size(); i++)
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |