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 debug
#define ll long long
#define maxn 200200
#define pii pair<int,int>
using namespace std;
int sz[3];
int id0,id1,id2;
int ans[maxn];
vector<int> L[maxn];
int vis[maxn];
map<pii,int> bad;
int color(int vx,int qtd,int to){
//qtd--;
//ans[vx] = to; debug("+%d\n",vx);
queue<int> Q;
Q.push(vx);
vis[vx] = 1;
while(qtd){
int nov = Q.front();
Q.pop();
ans[nov] = to;debug("+%d\n",nov);
qtd--;
for(int i=0;i<L[nov].size();i++){
int yy = L[nov][i];
if(bad[pii(nov,yy)]) continue;
if(!vis[yy]){
vis[yy] = 1; debug("push %d\n",yy);
Q.push(yy);
}
}
}
}
int pai[maxn];
int sub[maxn];
void dfs(int vx,int p=-1){
pai[vx] = p;
sub[vx] = 1;
for(int i=0;i<L[vx].size();i++)
if(L[vx][i] != p){
dfs(L[vx][i],vx);
sub[vx] += sub[L[vx][i]];
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
sz[0] = a;
sz[1] = b;
sz[2] = c;
if(p.size() == n){
p.pop_back();
}
vector<int> res;
for(int i=0;i<p.size();i++)
L[p[i]].pb(q[i]), L[q[i]].pb(p[i]);
vector<pii> vv;
for(int i=0;i<3;i++){
vv.pb(pii(sz[i],i));
}
sort(vv.begin(),vv.end());
id0 = vv[0].second;
id1 = vv[1].second;
id2 = vv[2].second;
int look = 1;
for(int i=0;i<n;i++) ans[i] = id2+1;
if(sz[id0] == 1){
color(0,sz[id1],id1+1);
for(int i=0;i<n;i++)
if(ans[i] == id2+1){
ans[i] = id0+1;
break;
}
}
else {
dfs(0);
for(int i=0;i<n && look;i++)
if(sub[i] >= a && sub[i] <= n-a){
bad[pii(i,pai[i])] = bad[pii(pai[i],i)] = 1;
if(2*sub[i] <= n) {
color(i,sz[id0],id0+1);
color(pai[i],sz[id1],id1+1);
}
else {
color(pai[i],sz[id0],id0+1);
color(i,sz[id1],id1+1);
}
look = 0;
}
if(look == 1){
for(int i=0;i<n;i++) ans[i] = 0;
}
}
//for(int i=0;i<a;i++) ans[i] = 1;
///for(int i=a;i<a+b;i++) ans[i] = 2;
//for(int i=a+b;i<n;i++) ans[i] = 3;
for(int i=0;i<n;i++) res.pb(ans[i]);
return res;
}
Compilation message (stderr)
split.cpp: In function 'int color(int, int, int)':
split.cpp:31:31: warning: left operand of comma operator has no effect [-Wunused-value]
ans[nov] = to;debug("+%d\n",nov);
^~~
split.cpp:33:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<L[nov].size();i++){
~^~~~~~~~~~~~~~
split.cpp:37:36: warning: left operand of comma operator has no effect [-Wunused-value]
vis[yy] = 1; debug("push %d\n",yy);
^~
split.cpp:43:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
split.cpp: In function 'void dfs(int, int)':
split.cpp:50:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<L[vx].size();i++)
~^~~~~~~~~~~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:63:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(p.size() == n){
~~~~~~~~~^~~~
split.cpp:68:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
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... |