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>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
vector<int>v[100005],cn[100005];
vector<pii>gr;
bitset<100005>vis;
int ch[100005],mn,pos,rr,re[100005];
void dfs(int N)
{
vis[N]=true;
ch[N]=1;
for(int i=0;i<v[N].size();i++)
{
if((!vis[v[N][i]])&&re[v[N][i]]==0)
{
dfs(v[N][i]);
ch[N]+=ch[v[N][i]];
cn[N].pb(v[N][i]);
}
}
return;
}
void grdiv(int N,int ty)
{
if(rr>=gr[ty].F||re[N]!=0)return;
ch[N]=0;
rr++,re[N]=gr[ty].S;
for(int i=0;i<cn[N].size();i++)
{
grdiv(cn[N][i],ty);
}
return;
}
vector<int>find_split(int n,int a,int b,int c,vector<int>p,vector<int>q)
{
vector<int>ans(n);
gr.pb({a,1});
gr.pb({b,2});
gr.pb({c,3});
sort(all(gr));
for(int i=0;i<p.size();i++)
{
v[p[i]].pb(q[i]);
v[q[i]].pb(p[i]);
}
dfs(0);
mn=imx,rr=1;
for(int i=0;i<n;i++)
{
if(ch[i]>=gr[0].F&&ch[i]<mn)
{
mn=ch[i];
pos=i;
}
}
re[pos]=gr[0].S,ch[pos]=0;
for(int i=0;i<cn[pos].size();i++)grdiv(cn[pos][i],0);
dfs(0);
mn=imx,rr=1;
for(int i=0;i<n;i++)
{
if(ch[i]>=gr[0].F&&ch[i]<mn)
{
mn=ch[i];
pos=i;
}
}
if(mn!=imx)
{
re[pos]=gr[1].S,ch[pos]=0;
for(int i=0;i<cn[pos].size();i++)grdiv(cn[pos][i],1);
for(int i=0;i<n;i++)
{
if(re[i]==0)ans[i]=gr[2].S;
else ans[i]=re[i];
}
}
return ans;
}
Compilation message (stderr)
split.cpp: In function 'void dfs(int)':
split.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0;i<v[N].size();i++)
| ~^~~~~~~~~~~~
split.cpp: In function 'void grdiv(int, int)':
split.cpp:40:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i=0;i<cn[N].size();i++)
| ~^~~~~~~~~~~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:54:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i=0;i<p.size();i++)
| ~^~~~~~~~~
split.cpp:70:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i=0;i<cn[pos].size();i++)grdiv(cn[pos][i],0);
| ~^~~~~~~~~~~~~~~
split.cpp:84:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int i=0;i<cn[pos].size();i++)grdiv(cn[pos][i],1);
| ~^~~~~~~~~~~~~~~
# | 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... |