#include "split.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for (int i=1;i<=n;i++)
#define REP(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define mp make_pair
#define sz(x) ((int)(x).size())
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll linf=1e18;
const int N=100000+10;
const int M=200000+10;
const double eps=1e-5;
const int mo=1e9+7;
int n,m,A,B,C,a,b,c;
int head[N];
int nxt[2*M];
int to[2*M];
int cnt;
int dfn[N],nn;
int f[N];
int sz[N];
bool colored[N];
bool found=0;
bool vis[N];
int remain;
int colors[4];
int ans[N];
bool taken[N];
bool tree_edge[2*M];
void color(int x,int fa) {
colored[x]=1;
int y;
for (int i=head[x];i;i=nxt[i]) if (tree_edge[i]) {
y=to[i];
if (y!=fa) {
color(y,x);
}
}
}
void add(int x,int y) {
nxt[++cnt]=head[x];
to[cnt]=y;
head[x]=cnt;
nxt[++cnt]=head[y];
to[cnt]=x;
head[y]=cnt;
}
void set_edge(int e) {
if (e%2==0) tree_edge[e]=tree_edge[e-1]=1;
else tree_edge[e]=tree_edge[e+1]=1;
}
void dfs(int x,int fa) {
sz[x]=1;
dfn[x]=++nn;
f[x]=nn;
int y;
for (int i=head[x];i;i=nxt[i]) {
y=to[i];
if (y!=fa) {
if (!dfn[y]) {
set_edge(i);
dfs(y,x);
sz[x]+=sz[y];
f[x]=min(f[x],f[y]);
} else {
f[x]=min(f[x],dfn[y]);
}
}
}
}
void solve(int x,int fa) {
int y;
int p=0,cntb=0,sum=0;
for (int i=head[x];i;i=nxt[i]) if (tree_edge[i]) {
y=to[i];
if (y!=fa) {
if (sz[y]>=b) {
p=y;
cntb++;
}
}
}
if (cntb>=2) {
color(p,x);
found=1;
return;
} else if (cntb==1) {
if (n-sz[p]>=c) {
color(p,x);
found=1;
return;
} else {
solve(p,x);
}
} else {
sum=n-sz[x];
for (int i=head[x];i;i=nxt[i]) if (tree_edge[i]) {
y=to[i];
if (y!=fa) {
if (f[y]<dfn[x]) {
// 有前向边连接上树
sum+=sz[y];
taken[y]=1;
if (sum>=c) {
// find
// 注意find处理完后要退出循环
for (int j=head[x];j;j=nxt[j]) if (tree_edge[j]) {
y=to[j];
if (y!=fa) {
if (!taken[y]) {
color(y,x);
}
}
}
colored[x]=1;
found=1;
return;
}
}
}
}
for (int i=head[x];i;i=nxt[i]) if (tree_edge[i]) {
y=to[i];
if (y!=fa) {
if (f[y]>=dfn[x]&&sz[y]>=c) {
// find
color(y,x);
found=1;
return;
}
}
}
// 无解
}
}
void grow(int x) {
if (remain==0) {
return;
}
vis[x]=1;
remain--;
if (remain<=0) {
return;
}
int y;
for (int i=head[x];i;i=nxt[i]) {
y=to[i];
if (!vis[y]&&colored[y]==colored[x]) {
grow(y);
}
}
}
vector<int> find_split(int N, int A, int B, int C, vector<int> P, vector<int> Q) {
n=N,m=int(P.size()),a=A,b=B,c=C;
REP(i,0,2) colors[i]=i+1;
vector<int> res;
if (c>a) {
swap(c,a);
swap(colors[2],colors[0]);
}
if (c>b){
swap(c,b);
swap(colors[2],colors[1]);
}
if (b>a) {
swap(a,b);
swap(colors[0],colors[1]);
}
for (int i=0;i<m;i++) add(P[i]+1,Q[i]+1);
int maxsz=0,p=0,root=1;
dfs(root,0);
int y;
for (int i=head[root];i;i=nxt[i]) if (tree_edge[i]) {
y=to[i];
if (maxsz<sz[y]) {
maxsz=sz[y];
p=y;
}
}
if (c<=maxsz&&maxsz<=a) {
color(p,root);
found=1;
} else if (maxsz<c) {
// 无解
} else if (maxsz>a) {
if (n-maxsz>=c) {
color(p,root);
found=1;
} else if (n-maxsz<c) {
solve(p,root);
}
}
if (found) {
int s=0;
FOR(i,n) if (colored[i]) s++;
if (n-s>=s) {
FOR(i,n) if (colored[i]) {
remain=c;
grow(i);
FOR(j,n) if (vis[j]) ans[j]=colors[2];
break;
}
FOR(i,n) if (!colored[i]) {
remain=b;
grow(i);
FOR(j,n) {
if (vis[j]&&!ans[j]) {
ans[j]=colors[1];
} else if (!vis[j]) {
ans[j]=colors[0];
}
}
break;
}
} else {
FOR(i,n) if (colored[i]) {
remain=b;
grow(i);
FOR(j,n) if (vis[j]) ans[j]=colors[1];
break;
}
FOR(i,n) if (!colored[i]) {
remain=c;
grow(i);
FOR(j,n) {
if (vis[j]&&!ans[j]) {
ans[j]=colors[2];
} else if (!vis[j]) {
ans[j]=colors[0];
}
}
break;
}
}
FOR(i,n) res.pb(ans[i]);
} else {
FOR(i,n) res.pb(0);
}
return res;
}
/*
int main() {
int n, m, a, b, c;
assert(5 == scanf("%d%d%d%d%d", &n, &m, &a, &b, &c));
vector<int> p(m), q(m);
for (int i=0; i<m; i++)
assert(2 == scanf("%d%d", &p[i], &q[i]));
fclose(stdin);
vector<int> result = find_split(n, a, b, c, p, q);
for (int i=0; i<(int)result.size(); i++)
printf("%s%d", ((i>0)?" ":""), result[i]);
printf("\n");
fclose(stdout);
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
ok, correct split |
2 |
Correct |
1 ms |
384 KB |
ok, correct split |
3 |
Correct |
1 ms |
384 KB |
ok, correct split |
4 |
Correct |
1 ms |
384 KB |
ok, correct split |
5 |
Correct |
1 ms |
384 KB |
ok, correct split |
6 |
Correct |
1 ms |
384 KB |
ok, correct split |
7 |
Correct |
68 ms |
10868 KB |
ok, correct split |
8 |
Correct |
63 ms |
9460 KB |
ok, correct split |
9 |
Correct |
63 ms |
9204 KB |
ok, correct split |
10 |
Correct |
64 ms |
10996 KB |
ok, correct split |
11 |
Correct |
67 ms |
11124 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
ok, correct split |
2 |
Correct |
1 ms |
384 KB |
ok, correct split |
3 |
Correct |
1 ms |
384 KB |
ok, correct split |
4 |
Correct |
86 ms |
10100 KB |
ok, correct split |
5 |
Correct |
59 ms |
6392 KB |
ok, correct split |
6 |
Correct |
63 ms |
11124 KB |
ok, correct split |
7 |
Correct |
63 ms |
9460 KB |
ok, correct split |
8 |
Correct |
104 ms |
9460 KB |
ok, correct split |
9 |
Correct |
65 ms |
6644 KB |
ok, correct split |
10 |
Correct |
45 ms |
6388 KB |
ok, correct split |
11 |
Correct |
47 ms |
6524 KB |
ok, correct split |
12 |
Correct |
48 ms |
6388 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
ok, correct split |
2 |
Correct |
59 ms |
6516 KB |
ok, correct split |
3 |
Correct |
23 ms |
2944 KB |
ok, correct split |
4 |
Correct |
0 ms |
384 KB |
ok, correct split |
5 |
Correct |
62 ms |
8052 KB |
ok, correct split |
6 |
Correct |
61 ms |
7924 KB |
ok, correct split |
7 |
Correct |
62 ms |
7796 KB |
ok, correct split |
8 |
Correct |
61 ms |
8564 KB |
ok, correct split |
9 |
Correct |
64 ms |
7668 KB |
ok, correct split |
10 |
Correct |
17 ms |
2432 KB |
ok, no valid answer |
11 |
Correct |
25 ms |
3200 KB |
ok, no valid answer |
12 |
Correct |
48 ms |
6004 KB |
ok, no valid answer |
13 |
Correct |
49 ms |
5876 KB |
ok, no valid answer |
14 |
Correct |
45 ms |
5876 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
ok, correct split |
2 |
Correct |
0 ms |
384 KB |
ok, no valid answer |
3 |
Correct |
0 ms |
384 KB |
ok, correct split |
4 |
Correct |
1 ms |
384 KB |
ok, correct split |
5 |
Correct |
1 ms |
384 KB |
ok, correct split |
6 |
Correct |
0 ms |
384 KB |
ok, correct split |
7 |
Correct |
0 ms |
384 KB |
ok, correct split |
8 |
Correct |
0 ms |
384 KB |
ok, correct split |
9 |
Correct |
3 ms |
640 KB |
ok, correct split |
10 |
Correct |
3 ms |
640 KB |
ok, correct split |
11 |
Correct |
1 ms |
384 KB |
ok, correct split |
12 |
Correct |
3 ms |
640 KB |
ok, correct split |
13 |
Correct |
1 ms |
512 KB |
ok, correct split |
14 |
Correct |
1 ms |
384 KB |
ok, correct split |
15 |
Correct |
1 ms |
384 KB |
ok, correct split |
16 |
Correct |
1 ms |
384 KB |
ok, correct split |
17 |
Correct |
1 ms |
384 KB |
ok, correct split |
18 |
Correct |
1 ms |
384 KB |
ok, correct split |
19 |
Correct |
1 ms |
384 KB |
ok, correct split |
20 |
Correct |
1 ms |
512 KB |
ok, correct split |
21 |
Correct |
2 ms |
584 KB |
ok, correct split |
22 |
Correct |
2 ms |
640 KB |
ok, correct split |
23 |
Correct |
2 ms |
640 KB |
ok, correct split |
24 |
Correct |
2 ms |
640 KB |
ok, correct split |
25 |
Correct |
2 ms |
640 KB |
ok, correct split |
26 |
Correct |
3 ms |
640 KB |
ok, correct split |
27 |
Correct |
3 ms |
640 KB |
ok, correct split |
28 |
Correct |
3 ms |
640 KB |
ok, correct split |
29 |
Correct |
1 ms |
384 KB |
ok, correct split |
30 |
Correct |
3 ms |
640 KB |
ok, correct split |
31 |
Correct |
1 ms |
512 KB |
ok, correct split |
32 |
Correct |
1 ms |
384 KB |
ok, correct split |
33 |
Correct |
1 ms |
384 KB |
ok, correct split |
34 |
Correct |
2 ms |
640 KB |
ok, correct split |
35 |
Correct |
2 ms |
640 KB |
ok, correct split |
36 |
Correct |
2 ms |
512 KB |
ok, correct split |
37 |
Correct |
3 ms |
640 KB |
ok, correct split |
38 |
Correct |
3 ms |
640 KB |
ok, correct split |
39 |
Correct |
3 ms |
640 KB |
ok, correct split |
40 |
Correct |
3 ms |
640 KB |
ok, correct split |
41 |
Correct |
2 ms |
512 KB |
ok, correct split |
42 |
Correct |
2 ms |
512 KB |
ok, correct split |
43 |
Correct |
3 ms |
640 KB |
ok, correct split |
44 |
Correct |
3 ms |
640 KB |
ok, correct split |
45 |
Correct |
3 ms |
640 KB |
ok, correct split |
46 |
Correct |
2 ms |
640 KB |
ok, correct split |
47 |
Correct |
2 ms |
512 KB |
ok, no valid answer |
48 |
Correct |
2 ms |
640 KB |
ok, correct split |
49 |
Correct |
2 ms |
640 KB |
ok, correct split |
50 |
Correct |
1 ms |
384 KB |
ok, no valid answer |
51 |
Correct |
1 ms |
384 KB |
ok, no valid answer |
52 |
Correct |
2 ms |
512 KB |
ok, no valid answer |
53 |
Correct |
3 ms |
640 KB |
ok, no valid answer |
54 |
Correct |
2 ms |
512 KB |
ok, no valid answer |
55 |
Correct |
2 ms |
640 KB |
ok, no valid answer |
56 |
Correct |
2 ms |
640 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
ok, correct split |
2 |
Correct |
1 ms |
384 KB |
ok, correct split |
3 |
Correct |
1 ms |
384 KB |
ok, correct split |
4 |
Correct |
1 ms |
384 KB |
ok, correct split |
5 |
Correct |
1 ms |
384 KB |
ok, correct split |
6 |
Correct |
1 ms |
384 KB |
ok, correct split |
7 |
Correct |
68 ms |
10868 KB |
ok, correct split |
8 |
Correct |
63 ms |
9460 KB |
ok, correct split |
9 |
Correct |
63 ms |
9204 KB |
ok, correct split |
10 |
Correct |
64 ms |
10996 KB |
ok, correct split |
11 |
Correct |
67 ms |
11124 KB |
ok, correct split |
12 |
Correct |
1 ms |
384 KB |
ok, correct split |
13 |
Correct |
1 ms |
384 KB |
ok, correct split |
14 |
Correct |
1 ms |
384 KB |
ok, correct split |
15 |
Correct |
86 ms |
10100 KB |
ok, correct split |
16 |
Correct |
59 ms |
6392 KB |
ok, correct split |
17 |
Correct |
63 ms |
11124 KB |
ok, correct split |
18 |
Correct |
63 ms |
9460 KB |
ok, correct split |
19 |
Correct |
104 ms |
9460 KB |
ok, correct split |
20 |
Correct |
65 ms |
6644 KB |
ok, correct split |
21 |
Correct |
45 ms |
6388 KB |
ok, correct split |
22 |
Correct |
47 ms |
6524 KB |
ok, correct split |
23 |
Correct |
48 ms |
6388 KB |
ok, correct split |
24 |
Correct |
1 ms |
384 KB |
ok, correct split |
25 |
Correct |
59 ms |
6516 KB |
ok, correct split |
26 |
Correct |
23 ms |
2944 KB |
ok, correct split |
27 |
Correct |
0 ms |
384 KB |
ok, correct split |
28 |
Correct |
62 ms |
8052 KB |
ok, correct split |
29 |
Correct |
61 ms |
7924 KB |
ok, correct split |
30 |
Correct |
62 ms |
7796 KB |
ok, correct split |
31 |
Correct |
61 ms |
8564 KB |
ok, correct split |
32 |
Correct |
64 ms |
7668 KB |
ok, correct split |
33 |
Correct |
17 ms |
2432 KB |
ok, no valid answer |
34 |
Correct |
25 ms |
3200 KB |
ok, no valid answer |
35 |
Correct |
48 ms |
6004 KB |
ok, no valid answer |
36 |
Correct |
49 ms |
5876 KB |
ok, no valid answer |
37 |
Correct |
45 ms |
5876 KB |
ok, no valid answer |
38 |
Correct |
0 ms |
384 KB |
ok, correct split |
39 |
Correct |
0 ms |
384 KB |
ok, no valid answer |
40 |
Correct |
0 ms |
384 KB |
ok, correct split |
41 |
Correct |
1 ms |
384 KB |
ok, correct split |
42 |
Correct |
1 ms |
384 KB |
ok, correct split |
43 |
Correct |
0 ms |
384 KB |
ok, correct split |
44 |
Correct |
0 ms |
384 KB |
ok, correct split |
45 |
Correct |
0 ms |
384 KB |
ok, correct split |
46 |
Correct |
3 ms |
640 KB |
ok, correct split |
47 |
Correct |
3 ms |
640 KB |
ok, correct split |
48 |
Correct |
1 ms |
384 KB |
ok, correct split |
49 |
Correct |
3 ms |
640 KB |
ok, correct split |
50 |
Correct |
1 ms |
512 KB |
ok, correct split |
51 |
Correct |
1 ms |
384 KB |
ok, correct split |
52 |
Correct |
1 ms |
384 KB |
ok, correct split |
53 |
Correct |
1 ms |
384 KB |
ok, correct split |
54 |
Correct |
1 ms |
384 KB |
ok, correct split |
55 |
Correct |
1 ms |
384 KB |
ok, correct split |
56 |
Correct |
1 ms |
384 KB |
ok, correct split |
57 |
Correct |
1 ms |
512 KB |
ok, correct split |
58 |
Correct |
2 ms |
584 KB |
ok, correct split |
59 |
Correct |
2 ms |
640 KB |
ok, correct split |
60 |
Correct |
2 ms |
640 KB |
ok, correct split |
61 |
Correct |
2 ms |
640 KB |
ok, correct split |
62 |
Correct |
2 ms |
640 KB |
ok, correct split |
63 |
Correct |
3 ms |
640 KB |
ok, correct split |
64 |
Correct |
3 ms |
640 KB |
ok, correct split |
65 |
Correct |
3 ms |
640 KB |
ok, correct split |
66 |
Correct |
1 ms |
384 KB |
ok, correct split |
67 |
Correct |
3 ms |
640 KB |
ok, correct split |
68 |
Correct |
1 ms |
512 KB |
ok, correct split |
69 |
Correct |
1 ms |
384 KB |
ok, correct split |
70 |
Correct |
1 ms |
384 KB |
ok, correct split |
71 |
Correct |
2 ms |
640 KB |
ok, correct split |
72 |
Correct |
2 ms |
640 KB |
ok, correct split |
73 |
Correct |
2 ms |
512 KB |
ok, correct split |
74 |
Correct |
3 ms |
640 KB |
ok, correct split |
75 |
Correct |
3 ms |
640 KB |
ok, correct split |
76 |
Correct |
3 ms |
640 KB |
ok, correct split |
77 |
Correct |
3 ms |
640 KB |
ok, correct split |
78 |
Correct |
2 ms |
512 KB |
ok, correct split |
79 |
Correct |
2 ms |
512 KB |
ok, correct split |
80 |
Correct |
3 ms |
640 KB |
ok, correct split |
81 |
Correct |
3 ms |
640 KB |
ok, correct split |
82 |
Correct |
3 ms |
640 KB |
ok, correct split |
83 |
Correct |
2 ms |
640 KB |
ok, correct split |
84 |
Correct |
2 ms |
512 KB |
ok, no valid answer |
85 |
Correct |
2 ms |
640 KB |
ok, correct split |
86 |
Correct |
2 ms |
640 KB |
ok, correct split |
87 |
Correct |
1 ms |
384 KB |
ok, no valid answer |
88 |
Correct |
1 ms |
384 KB |
ok, no valid answer |
89 |
Correct |
2 ms |
512 KB |
ok, no valid answer |
90 |
Correct |
3 ms |
640 KB |
ok, no valid answer |
91 |
Correct |
2 ms |
512 KB |
ok, no valid answer |
92 |
Correct |
2 ms |
640 KB |
ok, no valid answer |
93 |
Correct |
2 ms |
640 KB |
ok, no valid answer |
94 |
Correct |
94 ms |
9844 KB |
ok, correct split |
95 |
Correct |
124 ms |
14836 KB |
ok, correct split |
96 |
Correct |
104 ms |
13172 KB |
ok, correct split |
97 |
Correct |
23 ms |
3456 KB |
ok, correct split |
98 |
Correct |
24 ms |
3584 KB |
ok, correct split |
99 |
Correct |
45 ms |
6264 KB |
ok, correct split |
100 |
Correct |
108 ms |
12404 KB |
ok, correct split |
101 |
Correct |
94 ms |
10996 KB |
ok, correct split |
102 |
Correct |
79 ms |
10740 KB |
ok, correct split |
103 |
Correct |
71 ms |
10228 KB |
ok, correct split |
104 |
Correct |
90 ms |
12148 KB |
ok, correct split |
105 |
Correct |
37 ms |
5112 KB |
ok, correct split |
106 |
Correct |
91 ms |
12148 KB |
ok, correct split |
107 |
Correct |
63 ms |
7796 KB |
ok, correct split |
108 |
Correct |
61 ms |
7668 KB |
ok, correct split |
109 |
Correct |
110 ms |
11764 KB |
ok, correct split |
110 |
Correct |
112 ms |
12148 KB |
ok, correct split |
111 |
Correct |
115 ms |
12148 KB |
ok, correct split |
112 |
Correct |
101 ms |
12148 KB |
ok, correct split |
113 |
Correct |
99 ms |
12148 KB |
ok, correct split |
114 |
Correct |
10 ms |
1792 KB |
ok, correct split |
115 |
Correct |
10 ms |
1664 KB |
ok, correct split |
116 |
Correct |
102 ms |
12148 KB |
ok, correct split |
117 |
Correct |
100 ms |
11896 KB |
ok, correct split |
118 |
Correct |
62 ms |
7668 KB |
ok, correct split |
119 |
Correct |
64 ms |
7668 KB |
ok, correct split |
120 |
Correct |
63 ms |
9844 KB |
ok, correct split |
121 |
Correct |
52 ms |
7156 KB |
ok, no valid answer |
122 |
Correct |
50 ms |
7028 KB |
ok, no valid answer |
123 |
Correct |
103 ms |
11892 KB |
ok, no valid answer |
124 |
Correct |
95 ms |
11764 KB |
ok, no valid answer |
125 |
Correct |
60 ms |
8436 KB |
ok, no valid answer |
126 |
Correct |
42 ms |
6516 KB |
ok, no valid answer |
127 |
Correct |
68 ms |
9476 KB |
ok, no valid answer |