//Never stop trying
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<str> vs;
typedef vector<ld> vd;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const int MOD = 1e9 + 7; //998244353
const ll INF = 1e9;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
#ifndef LOCAL
#include "split.h"
#endif
int N,A,B,C; //A<=B<=C
vi order,ans(MX);
vpi ed;
vi vec;
bool cmp(int i, int j){
return vec[i] < vec[j];
}
void reorder(int a, int b, int c){
vec.assign({0,a,b,c});
order.assign({0,1,2,3});
sort(all(order),cmp);
A=vec[order[1]],B=vec[order[2]],C=vec[order[3]];
}
vi par(MX),rnk(MX);
int findSet(int u){ return par[u]==u ? u : par[u]=findSet(par[u]); }
void unionSet(int u, int v){
u=findSet(u),v=findSet(v);
if(rnk[v]>rnk[u]) swap(u,v);
if(rnk[v]==rnk[u]) rnk[u]++;
par[v]=u;
}
vi adj[MX],sub(MX);
void dfs(int u, int p){
sub[u]=1;
for(auto v: adj[u]) if(v!=p){
dfs(v,u);
sub[u]+=sub[v];
}
}
int r;
void color(int u, int p, int c, int no){
ans[u]=c;
r--;
for(auto v: adj[u]) if(v!=p && v!=no && r>0){
color(v,u,c,no);
}
}
vi adj2[MX];
void assignComp(int u, int p){
for(auto v: adj[u]) if(v!=p){
adj2[u].pb(v);
adj2[v].pb(u);
assignComp(v,u);
}
}
vi colored,vis(MX);
void color2(int u){
vis[u]=1;
colored.pb(u);
r--;
for(auto v: adj2[u]) if(!vis[v] && r>0){
color2(v);
}
}
void color3(int u, int p){
ans[u]=2;
r--;
for(auto v: adj[u]) if(v!=p && ans[v]==0 && r>0) color3(v,u);
}
vi find_split(int n, int a, int b, int c, vi p, vi q){
N=n; ans.assign(N,0);
reorder(a,b,c);
FOR(i,0,N) par[i]=i,rnk[i]=0;
FOR(i,0,sz(p)){
int u=p[i],v=q[i];
if(findSet(u)!=findSet(v)){
unionSet(u,v);
adj[u].pb(v);
adj[v].pb(u);
}
else ed.eb(u,v);
}
dfs(0,0);
int C;
FOR(u,0,N){
bool y=true;
y&=(N-sub[u]<=N/2);
for(auto v: adj[u]) if(sub[v]<sub[u]) y&=(sub[v]<=N/2);
if(y){
C=u; break;
}
}
dfs(C,C);
c=-1; for(auto v: adj[C]) if(sub[v]>=A) c=v;
if(c!=-1){
r=A;
color(c,C,1,-1);
r=B;
color(C,C,2,c);
}
else{
for(auto c: adj[C]){
assignComp(c,C);
}
for(auto x: ed){
int u=x.fi,v=x.se;
if(u==C || v==C) continue;
adj2[u].pb(v);
adj2[v].pb(u);
}
FOR(i,0,N) vis[i]=0;
bool done=false;
FOR(i,0,N) if(vis[i]==0){
r=a;
colored.clear();
color2(i);
if(r<=0){
done=true;
for(auto u: colored) ans[u]=1;
break;
}
}
if(!done) return vi(N,0);
r=b;
color3(C,C);
}
FOR(i,0,N) if(!ans[i]) ans[i]=3;
FOR(i,0,N) ans[i]=order[ans[i]];
return ans;
}
#ifdef LOCAL
int main() {
boost; IO();
int N,M,a,b,c; cin>>N>>M>>a>>b>>c;
vi p(M),q(M);
FOR(i,0,M) cin>>p[i]>>q[i];
/*FOR(i,0,M) cin>>p[i];
FOR(i,0,M) cin>>q[i];*/
vi v=find_split(N,a,b,c,p,q);
for(auto x: v) cout << x << ' '; cout << endl;
return 0;
}
#endif
/*
9 10 4 2 3
0 0 0 0 0 0 1 3 4 5
1 2 3 4 6 8 7 7 5 6
*/
/*
12 12 4 4 4
0 1
0 4
0 6
0 9
1 2
1 3
4 5
6 7
6 8
9 10
9 11
3 5
*/
/* Careful!!!
.Array bounds
.Infinite loops
.Uninitialized variables / empty containers
.Multisets are shit
Some insights:
.Binary search
.Graph representation
.Write brute force code
.Change your approach
*/
Compilation message
split.cpp: In function 'vi find_split(int, int, int, int, vi, vi)':
split.cpp:156:6: warning: 'C' may be used uninitialized in this function [-Wmaybe-uninitialized]
156 | int C;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
13676 KB |
ok, correct split |
2 |
Correct |
9 ms |
13676 KB |
ok, correct split |
3 |
Correct |
9 ms |
13676 KB |
ok, correct split |
4 |
Correct |
9 ms |
13676 KB |
ok, correct split |
5 |
Correct |
9 ms |
13676 KB |
ok, correct split |
6 |
Correct |
10 ms |
13696 KB |
ok, correct split |
7 |
Correct |
120 ms |
25964 KB |
ok, correct split |
8 |
Correct |
108 ms |
24064 KB |
ok, correct split |
9 |
Correct |
115 ms |
23532 KB |
ok, correct split |
10 |
Correct |
109 ms |
25964 KB |
ok, correct split |
11 |
Correct |
121 ms |
24940 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
13676 KB |
ok, correct split |
2 |
Correct |
11 ms |
13676 KB |
ok, correct split |
3 |
Correct |
9 ms |
13676 KB |
ok, correct split |
4 |
Correct |
106 ms |
21732 KB |
ok, correct split |
5 |
Correct |
94 ms |
19948 KB |
ok, correct split |
6 |
Correct |
109 ms |
25964 KB |
ok, correct split |
7 |
Correct |
115 ms |
23916 KB |
ok, correct split |
8 |
Correct |
127 ms |
23136 KB |
ok, correct split |
9 |
Correct |
108 ms |
19948 KB |
ok, correct split |
10 |
Correct |
65 ms |
19940 KB |
ok, correct split |
11 |
Correct |
67 ms |
20068 KB |
ok, correct split |
12 |
Correct |
65 ms |
20324 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
13676 KB |
ok, correct split |
2 |
Correct |
89 ms |
20060 KB |
ok, correct split |
3 |
Correct |
35 ms |
16236 KB |
ok, correct split |
4 |
Correct |
9 ms |
13676 KB |
ok, correct split |
5 |
Correct |
114 ms |
21996 KB |
ok, correct split |
6 |
Correct |
114 ms |
21740 KB |
ok, correct split |
7 |
Correct |
109 ms |
21740 KB |
ok, correct split |
8 |
Correct |
111 ms |
22636 KB |
ok, correct split |
9 |
Correct |
114 ms |
21740 KB |
ok, correct split |
10 |
Correct |
37 ms |
16844 KB |
ok, no valid answer |
11 |
Correct |
53 ms |
18412 KB |
ok, no valid answer |
12 |
Correct |
89 ms |
21480 KB |
ok, no valid answer |
13 |
Correct |
126 ms |
23020 KB |
ok, no valid answer |
14 |
Correct |
64 ms |
20324 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
13676 KB |
ok, correct split |
2 |
Correct |
9 ms |
13676 KB |
ok, no valid answer |
3 |
Correct |
9 ms |
13676 KB |
ok, correct split |
4 |
Correct |
9 ms |
13676 KB |
ok, correct split |
5 |
Correct |
9 ms |
13676 KB |
ok, correct split |
6 |
Correct |
9 ms |
13676 KB |
ok, correct split |
7 |
Correct |
9 ms |
13676 KB |
ok, correct split |
8 |
Correct |
10 ms |
13676 KB |
ok, correct split |
9 |
Correct |
11 ms |
13932 KB |
ok, correct split |
10 |
Correct |
11 ms |
13932 KB |
ok, correct split |
11 |
Correct |
9 ms |
13676 KB |
ok, correct split |
12 |
Incorrect |
11 ms |
13932 KB |
invalid split: #1=800, #2=800, #3=801 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
13676 KB |
ok, correct split |
2 |
Correct |
9 ms |
13676 KB |
ok, correct split |
3 |
Correct |
9 ms |
13676 KB |
ok, correct split |
4 |
Correct |
9 ms |
13676 KB |
ok, correct split |
5 |
Correct |
9 ms |
13676 KB |
ok, correct split |
6 |
Correct |
10 ms |
13696 KB |
ok, correct split |
7 |
Correct |
120 ms |
25964 KB |
ok, correct split |
8 |
Correct |
108 ms |
24064 KB |
ok, correct split |
9 |
Correct |
115 ms |
23532 KB |
ok, correct split |
10 |
Correct |
109 ms |
25964 KB |
ok, correct split |
11 |
Correct |
121 ms |
24940 KB |
ok, correct split |
12 |
Correct |
9 ms |
13676 KB |
ok, correct split |
13 |
Correct |
11 ms |
13676 KB |
ok, correct split |
14 |
Correct |
9 ms |
13676 KB |
ok, correct split |
15 |
Correct |
106 ms |
21732 KB |
ok, correct split |
16 |
Correct |
94 ms |
19948 KB |
ok, correct split |
17 |
Correct |
109 ms |
25964 KB |
ok, correct split |
18 |
Correct |
115 ms |
23916 KB |
ok, correct split |
19 |
Correct |
127 ms |
23136 KB |
ok, correct split |
20 |
Correct |
108 ms |
19948 KB |
ok, correct split |
21 |
Correct |
65 ms |
19940 KB |
ok, correct split |
22 |
Correct |
67 ms |
20068 KB |
ok, correct split |
23 |
Correct |
65 ms |
20324 KB |
ok, correct split |
24 |
Correct |
9 ms |
13676 KB |
ok, correct split |
25 |
Correct |
89 ms |
20060 KB |
ok, correct split |
26 |
Correct |
35 ms |
16236 KB |
ok, correct split |
27 |
Correct |
9 ms |
13676 KB |
ok, correct split |
28 |
Correct |
114 ms |
21996 KB |
ok, correct split |
29 |
Correct |
114 ms |
21740 KB |
ok, correct split |
30 |
Correct |
109 ms |
21740 KB |
ok, correct split |
31 |
Correct |
111 ms |
22636 KB |
ok, correct split |
32 |
Correct |
114 ms |
21740 KB |
ok, correct split |
33 |
Correct |
37 ms |
16844 KB |
ok, no valid answer |
34 |
Correct |
53 ms |
18412 KB |
ok, no valid answer |
35 |
Correct |
89 ms |
21480 KB |
ok, no valid answer |
36 |
Correct |
126 ms |
23020 KB |
ok, no valid answer |
37 |
Correct |
64 ms |
20324 KB |
ok, no valid answer |
38 |
Correct |
9 ms |
13676 KB |
ok, correct split |
39 |
Correct |
9 ms |
13676 KB |
ok, no valid answer |
40 |
Correct |
9 ms |
13676 KB |
ok, correct split |
41 |
Correct |
9 ms |
13676 KB |
ok, correct split |
42 |
Correct |
9 ms |
13676 KB |
ok, correct split |
43 |
Correct |
9 ms |
13676 KB |
ok, correct split |
44 |
Correct |
9 ms |
13676 KB |
ok, correct split |
45 |
Correct |
10 ms |
13676 KB |
ok, correct split |
46 |
Correct |
11 ms |
13932 KB |
ok, correct split |
47 |
Correct |
11 ms |
13932 KB |
ok, correct split |
48 |
Correct |
9 ms |
13676 KB |
ok, correct split |
49 |
Incorrect |
11 ms |
13932 KB |
invalid split: #1=800, #2=800, #3=801 |
50 |
Halted |
0 ms |
0 KB |
- |