#include <bits/stdc++.h>
#define split
using namespace std;
const int N = 100005;
int n;
pair <int, int> a, b, c;
vector <int> C, adj[N], E[N];
int sz[N], check[N], d[N];
int times, low[N], num[N];
void dfs(int u, int p)
{
num[u] = low[u] = ++times;
sz[u] = 1;
check[u] = 1;
for (auto v: adj[u])
{
if (v == p) continue;
if (!num[v])
{
E[u].push_back(v);
d[v] = d[u] + 1;
dfs(v, u);
sz[u] += sz[v];
low[u] = min(low[u], low[v]);
if (sz[v] >= a.first) check[u] = 0;
}
else low[u] = min(low[u], num[v]);
}
}
void paint(int u, int num, int cl)
{
queue <int> q;
q.push(u);
int cnt = 0;
if (!C[u])
{
C[u] = cl;
cnt = 1;
}
if (cnt == num) return;
while (!q.empty())
{
int u = q.front();
q.pop();
for (auto v: E[u])
if (!C[v])
{
++cnt;
C[v] = cl;
q.push(v);
if (num == cnt) return;
}
}
}
vector <int> find_split(int _n, int _a, int _b, int _c, vector <int> u, vector <int> v)
{
n = _n;
a = {_a, 1}, b = {_b, 2}, c = {_c, 3};
if (a > b) swap(a, b);
if (a > c) swap(a, c);
if (b > c) swap(b, c);
assert(a <= b && b <= c);
int m = (int)v.size();
C = vector <int> (n, 0);
for (int i = 0; i < m; i ++)
{
adj[v[i]].push_back(u[i]);
adj[u[i]].push_back(v[i]);
}
dfs(0, 0);
for (int u = 0; u < n; ++u)
{
if (check[u] && sz[u] >= a.first && n - sz[u] >= a.first)
{
if (sz[u] <= n - sz[u])
{
paint(u, a.first, a.second);
paint(0, b.first, b.second);
}
else
{
paint(u, b.first, b.second);
paint(0, a.first, a.second);
}
for (int i = 0; i < n; ++i)
if (!C[i]) C[i] = c.second;
return C;
}
}
for (int u = 0; u < n; ++u)
if (check[u] && n - sz[u] < a.first)
{
int cnt = 0;
for (auto v: E[u])
if (low[v] < num[u]) cnt += sz[v];
if (cnt + n - sz[u] < a.first) continue;
C[u] = b.second;
paint(0, a.first, a.second);
cnt = n - sz[u];
for (auto v: E[u])
{
if (low[v] < num[u] && cnt + sz[v] <= a.first)
{
paint(v, a.first, a.second);
cnt += sz[v];
if (cnt == a.first) break;
else continue;
}
if (low[v] < num[u] && cnt + sz[v] > a.first)
{
int pivot = num[u];
queue <int> q;
vector <int> backward;
q.push(v);
while (!q.empty())
{
int u = q.front();
q.pop();
int ok = 0;
for (auto v: E[u])
{
if (low[v] < pivot)
{
ok = 1;
q.push(v);
}
}
if (!ok) backward.push_back(u);
}
for (auto root: backward)
{
q.push(root);
while (!q.empty())
{
int u = q.front();
q.pop();
++cnt;
C[u] = a.second;
if (cnt == a.first) goto label;
assert(cnt < a.first);
for (auto v: E[u])
q.push(v);
}
}
q.push(v);
stack <int> stk;
while (!q.empty())
{
int u = q.front();
q.pop();
stk.push(u);
for (auto v: E[u])
if (!C[v])
q.push(v);
}
while (!stk.empty())
{
int u = stk.top();
stk.pop();
C[u] = a.second;
++cnt;
if (cnt == a.first) goto label;
assert(cnt < a.first);
}
}
}
label:;
C[u] = 0;
paint(u, b.first, b.second);
for (int i = 0; i < n; ++i)
if (!C[i]) C[i] = c.second;
return C;
}
return C;
}
#ifdef split
#include <split.h>
#else
int main() {
freopen("split.inp", "r", stdin);
freopen("split.out", "w", stdout);
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]));
vector <int> result = find_split(n, a, b, c, p, q);
for (int i = 0; i < result.size(); ++i)
printf("%s%d", ((i > 0) ? " " : ""), result[i]);
printf("\n");
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
ok, correct split |
2 |
Correct |
4 ms |
4992 KB |
ok, correct split |
3 |
Correct |
4 ms |
4992 KB |
ok, correct split |
4 |
Correct |
4 ms |
4992 KB |
ok, correct split |
5 |
Correct |
4 ms |
4992 KB |
ok, correct split |
6 |
Correct |
4 ms |
4992 KB |
ok, correct split |
7 |
Correct |
129 ms |
24568 KB |
ok, correct split |
8 |
Correct |
131 ms |
21880 KB |
ok, correct split |
9 |
Correct |
124 ms |
20984 KB |
ok, correct split |
10 |
Correct |
128 ms |
25008 KB |
ok, correct split |
11 |
Correct |
135 ms |
25000 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
ok, correct split |
2 |
Correct |
3 ms |
4992 KB |
ok, correct split |
3 |
Correct |
4 ms |
4992 KB |
ok, correct split |
4 |
Correct |
157 ms |
19960 KB |
ok, correct split |
5 |
Correct |
124 ms |
14200 KB |
ok, correct split |
6 |
Correct |
123 ms |
24952 KB |
ok, correct split |
7 |
Correct |
126 ms |
21624 KB |
ok, correct split |
8 |
Correct |
176 ms |
16760 KB |
ok, correct split |
9 |
Correct |
121 ms |
15840 KB |
ok, correct split |
10 |
Correct |
69 ms |
13424 KB |
ok, correct split |
11 |
Correct |
70 ms |
13484 KB |
ok, correct split |
12 |
Correct |
73 ms |
13456 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
ok, correct split |
2 |
Correct |
107 ms |
14176 KB |
ok, correct split |
3 |
Correct |
36 ms |
8696 KB |
ok, correct split |
4 |
Correct |
4 ms |
4992 KB |
ok, correct split |
5 |
Correct |
123 ms |
18680 KB |
ok, correct split |
6 |
Correct |
125 ms |
18424 KB |
ok, correct split |
7 |
Correct |
122 ms |
18168 KB |
ok, correct split |
8 |
Correct |
132 ms |
19832 KB |
ok, correct split |
9 |
Correct |
125 ms |
18040 KB |
ok, correct split |
10 |
Correct |
29 ms |
8064 KB |
ok, no valid answer |
11 |
Correct |
47 ms |
9592 KB |
ok, no valid answer |
12 |
Correct |
82 ms |
13556 KB |
ok, no valid answer |
13 |
Correct |
100 ms |
14200 KB |
ok, no valid answer |
14 |
Correct |
70 ms |
13480 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
ok, correct split |
2 |
Correct |
3 ms |
4992 KB |
ok, no valid answer |
3 |
Correct |
3 ms |
4992 KB |
ok, correct split |
4 |
Correct |
4 ms |
4992 KB |
ok, correct split |
5 |
Correct |
4 ms |
4992 KB |
ok, correct split |
6 |
Correct |
4 ms |
4992 KB |
ok, correct split |
7 |
Correct |
4 ms |
4992 KB |
ok, correct split |
8 |
Correct |
4 ms |
5120 KB |
ok, correct split |
9 |
Correct |
8 ms |
5376 KB |
ok, correct split |
10 |
Correct |
6 ms |
5376 KB |
ok, correct split |
11 |
Correct |
4 ms |
4992 KB |
ok, correct split |
12 |
Correct |
6 ms |
5376 KB |
ok, correct split |
13 |
Correct |
4 ms |
4992 KB |
ok, correct split |
14 |
Correct |
3 ms |
4992 KB |
ok, correct split |
15 |
Correct |
4 ms |
4992 KB |
ok, correct split |
16 |
Correct |
4 ms |
4992 KB |
ok, correct split |
17 |
Correct |
3 ms |
4992 KB |
ok, correct split |
18 |
Correct |
4 ms |
4992 KB |
ok, correct split |
19 |
Correct |
5 ms |
5120 KB |
ok, correct split |
20 |
Correct |
5 ms |
5120 KB |
ok, correct split |
21 |
Correct |
6 ms |
5376 KB |
ok, correct split |
22 |
Correct |
5 ms |
5376 KB |
ok, correct split |
23 |
Correct |
5 ms |
5376 KB |
ok, correct split |
24 |
Correct |
5 ms |
5376 KB |
ok, correct split |
25 |
Correct |
5 ms |
5376 KB |
ok, correct split |
26 |
Correct |
7 ms |
5248 KB |
ok, correct split |
27 |
Correct |
6 ms |
5248 KB |
ok, correct split |
28 |
Correct |
7 ms |
5248 KB |
ok, correct split |
29 |
Correct |
4 ms |
5120 KB |
ok, correct split |
30 |
Correct |
6 ms |
5248 KB |
ok, correct split |
31 |
Correct |
4 ms |
5120 KB |
ok, correct split |
32 |
Correct |
4 ms |
5120 KB |
ok, correct split |
33 |
Correct |
4 ms |
5120 KB |
ok, correct split |
34 |
Correct |
5 ms |
5248 KB |
ok, correct split |
35 |
Correct |
6 ms |
5248 KB |
ok, correct split |
36 |
Correct |
5 ms |
5248 KB |
ok, correct split |
37 |
Correct |
6 ms |
5376 KB |
ok, correct split |
38 |
Correct |
7 ms |
5376 KB |
ok, correct split |
39 |
Correct |
6 ms |
5376 KB |
ok, correct split |
40 |
Correct |
6 ms |
5280 KB |
ok, correct split |
41 |
Correct |
5 ms |
5120 KB |
ok, correct split |
42 |
Correct |
5 ms |
5120 KB |
ok, correct split |
43 |
Correct |
6 ms |
5376 KB |
ok, correct split |
44 |
Correct |
6 ms |
5376 KB |
ok, correct split |
45 |
Correct |
6 ms |
5376 KB |
ok, correct split |
46 |
Correct |
5 ms |
5376 KB |
ok, correct split |
47 |
Correct |
5 ms |
5376 KB |
ok, no valid answer |
48 |
Correct |
5 ms |
5248 KB |
ok, correct split |
49 |
Correct |
5 ms |
5376 KB |
ok, correct split |
50 |
Correct |
4 ms |
4992 KB |
ok, no valid answer |
51 |
Correct |
4 ms |
4992 KB |
ok, no valid answer |
52 |
Correct |
5 ms |
5280 KB |
ok, no valid answer |
53 |
Correct |
7 ms |
5376 KB |
ok, no valid answer |
54 |
Correct |
6 ms |
5248 KB |
ok, no valid answer |
55 |
Correct |
6 ms |
5248 KB |
ok, no valid answer |
56 |
Correct |
6 ms |
5248 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
ok, correct split |
2 |
Correct |
4 ms |
4992 KB |
ok, correct split |
3 |
Correct |
4 ms |
4992 KB |
ok, correct split |
4 |
Correct |
4 ms |
4992 KB |
ok, correct split |
5 |
Correct |
4 ms |
4992 KB |
ok, correct split |
6 |
Correct |
4 ms |
4992 KB |
ok, correct split |
7 |
Correct |
129 ms |
24568 KB |
ok, correct split |
8 |
Correct |
131 ms |
21880 KB |
ok, correct split |
9 |
Correct |
124 ms |
20984 KB |
ok, correct split |
10 |
Correct |
128 ms |
25008 KB |
ok, correct split |
11 |
Correct |
135 ms |
25000 KB |
ok, correct split |
12 |
Correct |
4 ms |
4992 KB |
ok, correct split |
13 |
Correct |
3 ms |
4992 KB |
ok, correct split |
14 |
Correct |
4 ms |
4992 KB |
ok, correct split |
15 |
Correct |
157 ms |
19960 KB |
ok, correct split |
16 |
Correct |
124 ms |
14200 KB |
ok, correct split |
17 |
Correct |
123 ms |
24952 KB |
ok, correct split |
18 |
Correct |
126 ms |
21624 KB |
ok, correct split |
19 |
Correct |
176 ms |
16760 KB |
ok, correct split |
20 |
Correct |
121 ms |
15840 KB |
ok, correct split |
21 |
Correct |
69 ms |
13424 KB |
ok, correct split |
22 |
Correct |
70 ms |
13484 KB |
ok, correct split |
23 |
Correct |
73 ms |
13456 KB |
ok, correct split |
24 |
Correct |
4 ms |
4992 KB |
ok, correct split |
25 |
Correct |
107 ms |
14176 KB |
ok, correct split |
26 |
Correct |
36 ms |
8696 KB |
ok, correct split |
27 |
Correct |
4 ms |
4992 KB |
ok, correct split |
28 |
Correct |
123 ms |
18680 KB |
ok, correct split |
29 |
Correct |
125 ms |
18424 KB |
ok, correct split |
30 |
Correct |
122 ms |
18168 KB |
ok, correct split |
31 |
Correct |
132 ms |
19832 KB |
ok, correct split |
32 |
Correct |
125 ms |
18040 KB |
ok, correct split |
33 |
Correct |
29 ms |
8064 KB |
ok, no valid answer |
34 |
Correct |
47 ms |
9592 KB |
ok, no valid answer |
35 |
Correct |
82 ms |
13556 KB |
ok, no valid answer |
36 |
Correct |
100 ms |
14200 KB |
ok, no valid answer |
37 |
Correct |
70 ms |
13480 KB |
ok, no valid answer |
38 |
Correct |
3 ms |
4992 KB |
ok, correct split |
39 |
Correct |
3 ms |
4992 KB |
ok, no valid answer |
40 |
Correct |
3 ms |
4992 KB |
ok, correct split |
41 |
Correct |
4 ms |
4992 KB |
ok, correct split |
42 |
Correct |
4 ms |
4992 KB |
ok, correct split |
43 |
Correct |
4 ms |
4992 KB |
ok, correct split |
44 |
Correct |
4 ms |
4992 KB |
ok, correct split |
45 |
Correct |
4 ms |
5120 KB |
ok, correct split |
46 |
Correct |
8 ms |
5376 KB |
ok, correct split |
47 |
Correct |
6 ms |
5376 KB |
ok, correct split |
48 |
Correct |
4 ms |
4992 KB |
ok, correct split |
49 |
Correct |
6 ms |
5376 KB |
ok, correct split |
50 |
Correct |
4 ms |
4992 KB |
ok, correct split |
51 |
Correct |
3 ms |
4992 KB |
ok, correct split |
52 |
Correct |
4 ms |
4992 KB |
ok, correct split |
53 |
Correct |
4 ms |
4992 KB |
ok, correct split |
54 |
Correct |
3 ms |
4992 KB |
ok, correct split |
55 |
Correct |
4 ms |
4992 KB |
ok, correct split |
56 |
Correct |
5 ms |
5120 KB |
ok, correct split |
57 |
Correct |
5 ms |
5120 KB |
ok, correct split |
58 |
Correct |
6 ms |
5376 KB |
ok, correct split |
59 |
Correct |
5 ms |
5376 KB |
ok, correct split |
60 |
Correct |
5 ms |
5376 KB |
ok, correct split |
61 |
Correct |
5 ms |
5376 KB |
ok, correct split |
62 |
Correct |
5 ms |
5376 KB |
ok, correct split |
63 |
Correct |
7 ms |
5248 KB |
ok, correct split |
64 |
Correct |
6 ms |
5248 KB |
ok, correct split |
65 |
Correct |
7 ms |
5248 KB |
ok, correct split |
66 |
Correct |
4 ms |
5120 KB |
ok, correct split |
67 |
Correct |
6 ms |
5248 KB |
ok, correct split |
68 |
Correct |
4 ms |
5120 KB |
ok, correct split |
69 |
Correct |
4 ms |
5120 KB |
ok, correct split |
70 |
Correct |
4 ms |
5120 KB |
ok, correct split |
71 |
Correct |
5 ms |
5248 KB |
ok, correct split |
72 |
Correct |
6 ms |
5248 KB |
ok, correct split |
73 |
Correct |
5 ms |
5248 KB |
ok, correct split |
74 |
Correct |
6 ms |
5376 KB |
ok, correct split |
75 |
Correct |
7 ms |
5376 KB |
ok, correct split |
76 |
Correct |
6 ms |
5376 KB |
ok, correct split |
77 |
Correct |
6 ms |
5280 KB |
ok, correct split |
78 |
Correct |
5 ms |
5120 KB |
ok, correct split |
79 |
Correct |
5 ms |
5120 KB |
ok, correct split |
80 |
Correct |
6 ms |
5376 KB |
ok, correct split |
81 |
Correct |
6 ms |
5376 KB |
ok, correct split |
82 |
Correct |
6 ms |
5376 KB |
ok, correct split |
83 |
Correct |
5 ms |
5376 KB |
ok, correct split |
84 |
Correct |
5 ms |
5376 KB |
ok, no valid answer |
85 |
Correct |
5 ms |
5248 KB |
ok, correct split |
86 |
Correct |
5 ms |
5376 KB |
ok, correct split |
87 |
Correct |
4 ms |
4992 KB |
ok, no valid answer |
88 |
Correct |
4 ms |
4992 KB |
ok, no valid answer |
89 |
Correct |
5 ms |
5280 KB |
ok, no valid answer |
90 |
Correct |
7 ms |
5376 KB |
ok, no valid answer |
91 |
Correct |
6 ms |
5248 KB |
ok, no valid answer |
92 |
Correct |
6 ms |
5248 KB |
ok, no valid answer |
93 |
Correct |
6 ms |
5248 KB |
ok, no valid answer |
94 |
Correct |
131 ms |
17528 KB |
ok, correct split |
95 |
Correct |
187 ms |
22648 KB |
ok, correct split |
96 |
Correct |
166 ms |
21184 KB |
ok, correct split |
97 |
Correct |
39 ms |
8704 KB |
ok, correct split |
98 |
Correct |
40 ms |
8952 KB |
ok, correct split |
99 |
Correct |
64 ms |
11000 KB |
ok, correct split |
100 |
Correct |
172 ms |
17404 KB |
ok, correct split |
101 |
Correct |
155 ms |
16504 KB |
ok, correct split |
102 |
Correct |
138 ms |
16112 KB |
ok, correct split |
103 |
Correct |
132 ms |
15856 KB |
ok, correct split |
104 |
Correct |
136 ms |
15588 KB |
ok, correct split |
105 |
Correct |
63 ms |
10744 KB |
ok, correct split |
106 |
Correct |
146 ms |
15288 KB |
ok, correct split |
107 |
Correct |
117 ms |
14200 KB |
ok, correct split |
108 |
Correct |
113 ms |
14236 KB |
ok, correct split |
109 |
Correct |
188 ms |
16812 KB |
ok, correct split |
110 |
Correct |
176 ms |
17520 KB |
ok, correct split |
111 |
Correct |
163 ms |
17648 KB |
ok, correct split |
112 |
Correct |
157 ms |
16368 KB |
ok, correct split |
113 |
Correct |
163 ms |
16236 KB |
ok, correct split |
114 |
Correct |
22 ms |
6656 KB |
ok, correct split |
115 |
Correct |
16 ms |
6400 KB |
ok, correct split |
116 |
Correct |
200 ms |
17456 KB |
ok, correct split |
117 |
Correct |
168 ms |
17520 KB |
ok, correct split |
118 |
Correct |
123 ms |
15736 KB |
ok, correct split |
119 |
Correct |
120 ms |
15608 KB |
ok, correct split |
120 |
Correct |
124 ms |
20600 KB |
ok, correct split |
121 |
Correct |
105 ms |
14200 KB |
ok, no valid answer |
122 |
Correct |
104 ms |
14052 KB |
ok, no valid answer |
123 |
Correct |
182 ms |
17656 KB |
ok, no valid answer |
124 |
Correct |
171 ms |
17628 KB |
ok, no valid answer |
125 |
Correct |
101 ms |
14704 KB |
ok, no valid answer |
126 |
Correct |
62 ms |
12528 KB |
ok, no valid answer |
127 |
Correct |
125 ms |
15344 KB |
ok, no valid answer |