#include <bits/stdc++.h>
#include "split.h"
#define all(x) x.begin(),x.end()
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 100100;
vector<int> res;
vector<int> g[N], vc, children[N];
bool mrk[N];
int A[3], C[3], mrk_col[N], h[N], mn_h[N], pr[N], siz[N], mem = 0;
void dfs(int v, int p){
pr[v] = p;
siz[v] = 1;
mrk[v] = 1;
mn_h[v] = h[v];
for (int u : g[v]){
if (mrk[u]) continue;
children[v].PB(u);
h[u] = h[v] + 1;
dfs(u, v);
mn_h[v] = min(mn_h[v], mn_h[u]);
siz[v] += siz[u];
}
}
void col(int v, int cl){
mrk_col[v] = cl;
for (int u : children[v])
col(u, cl);
}
void DFS(int v, int cl, int rlc){
if (mrk[v]) return;
if (mem == 0) return;
mem--;
mrk[v] = 1;
res[v] = rlc;
for (int u : g[v])
if (mrk_col[u] == cl)
DFS(u, cl, rlc);
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
res.resize(n);
fill(all(res), 0);
for (int i = 0; i < sz(p); i++){
g[p[i]].PB(q[i]);
g[q[i]].PB(p[i]);
}
A[0] = a; A[1] = b; A[2] = c;
C[0] = 1; C[1] = 2; C[2] = 3;
if (A[0] > A[1]) {
swap(A[0], A[1]);
swap(C[0], C[1]);
}
if (A[1] > A[2]) {
swap(A[1], A[2]);
swap(C[1], C[2]);
}
if (A[0] > A[1]) {
swap(A[0], A[1]);
swap(C[0], C[1]);
}
dfs(0, -1);
for (int v = 0; v < n; v++){
bool ok = bool(siz[v] >= A[0]);
for (int u : children[v])
ok &= bool(siz[u] < A[0]);
if (!ok) continue;
col(0, 1);
col(v, 2);
int real_siz = siz[v];
for (int u : children[v])
if (mn_h[u] < h[v] && real_siz - siz[u] >= A[0]){
real_siz -= siz[u];
col(u, 1);
}
for (int t1 = 0; t1 < 2; t1++){
int t2 = 1 - t1;
if (real_siz >= A[t1] && n - real_siz >= A[t2]){
fill(mrk, mrk + n, 0);
mem = A[t2];
DFS(pr[v], 1, C[t2]);
mem = A[t1];
DFS(v, 2, C[t1]);
for (int &cr : res)
if (cr == 0)
cr = C[2];
return res;
}
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
ok, correct split |
2 |
Correct |
7 ms |
4992 KB |
ok, correct split |
3 |
Correct |
7 ms |
5120 KB |
ok, correct split |
4 |
Correct |
7 ms |
4992 KB |
ok, correct split |
5 |
Correct |
7 ms |
4992 KB |
ok, correct split |
6 |
Correct |
7 ms |
4992 KB |
ok, correct split |
7 |
Correct |
118 ms |
24312 KB |
ok, correct split |
8 |
Correct |
108 ms |
22056 KB |
ok, correct split |
9 |
Correct |
119 ms |
21368 KB |
ok, correct split |
10 |
Correct |
110 ms |
24696 KB |
ok, correct split |
11 |
Correct |
121 ms |
24696 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
ok, correct split |
2 |
Correct |
7 ms |
4992 KB |
ok, correct split |
3 |
Correct |
7 ms |
4992 KB |
ok, correct split |
4 |
Correct |
124 ms |
21112 KB |
ok, correct split |
5 |
Correct |
99 ms |
15480 KB |
ok, correct split |
6 |
Correct |
108 ms |
24696 KB |
ok, correct split |
7 |
Correct |
116 ms |
21880 KB |
ok, correct split |
8 |
Correct |
147 ms |
19064 KB |
ok, correct split |
9 |
Correct |
105 ms |
16888 KB |
ok, correct split |
10 |
Correct |
63 ms |
14192 KB |
ok, correct split |
11 |
Correct |
62 ms |
14192 KB |
ok, correct split |
12 |
Correct |
64 ms |
14576 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
ok, correct split |
2 |
Correct |
104 ms |
15480 KB |
ok, correct split |
3 |
Correct |
36 ms |
9208 KB |
ok, correct split |
4 |
Correct |
7 ms |
5096 KB |
ok, correct split |
5 |
Correct |
115 ms |
19448 KB |
ok, correct split |
6 |
Correct |
124 ms |
19324 KB |
ok, correct split |
7 |
Correct |
119 ms |
19064 KB |
ok, correct split |
8 |
Correct |
116 ms |
20344 KB |
ok, correct split |
9 |
Correct |
124 ms |
18808 KB |
ok, correct split |
10 |
Correct |
31 ms |
8440 KB |
ok, no valid answer |
11 |
Correct |
44 ms |
10232 KB |
ok, no valid answer |
12 |
Correct |
77 ms |
14836 KB |
ok, no valid answer |
13 |
Correct |
96 ms |
15352 KB |
ok, no valid answer |
14 |
Correct |
62 ms |
14704 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
ok, correct split |
2 |
Correct |
7 ms |
4992 KB |
ok, no valid answer |
3 |
Correct |
7 ms |
5024 KB |
ok, correct split |
4 |
Correct |
7 ms |
4992 KB |
ok, correct split |
5 |
Correct |
7 ms |
4992 KB |
ok, correct split |
6 |
Correct |
7 ms |
4992 KB |
ok, correct split |
7 |
Correct |
7 ms |
4992 KB |
ok, correct split |
8 |
Correct |
7 ms |
4992 KB |
ok, correct split |
9 |
Correct |
10 ms |
5376 KB |
ok, correct split |
10 |
Correct |
9 ms |
5376 KB |
ok, correct split |
11 |
Correct |
7 ms |
5120 KB |
ok, correct split |
12 |
Correct |
9 ms |
5376 KB |
ok, correct split |
13 |
Correct |
7 ms |
4992 KB |
ok, correct split |
14 |
Correct |
7 ms |
4992 KB |
ok, correct split |
15 |
Correct |
7 ms |
4992 KB |
ok, correct split |
16 |
Correct |
7 ms |
4992 KB |
ok, correct split |
17 |
Correct |
7 ms |
4992 KB |
ok, correct split |
18 |
Correct |
7 ms |
4992 KB |
ok, correct split |
19 |
Correct |
7 ms |
5120 KB |
ok, correct split |
20 |
Correct |
10 ms |
5376 KB |
ok, correct split |
21 |
Correct |
9 ms |
5504 KB |
ok, correct split |
22 |
Correct |
9 ms |
5376 KB |
ok, correct split |
23 |
Correct |
9 ms |
5504 KB |
ok, correct split |
24 |
Correct |
9 ms |
5504 KB |
ok, correct split |
25 |
Correct |
9 ms |
5376 KB |
ok, correct split |
26 |
Incorrect |
11 ms |
5376 KB |
jury found a solution, contestant did not |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
ok, correct split |
2 |
Correct |
7 ms |
4992 KB |
ok, correct split |
3 |
Correct |
7 ms |
5120 KB |
ok, correct split |
4 |
Correct |
7 ms |
4992 KB |
ok, correct split |
5 |
Correct |
7 ms |
4992 KB |
ok, correct split |
6 |
Correct |
7 ms |
4992 KB |
ok, correct split |
7 |
Correct |
118 ms |
24312 KB |
ok, correct split |
8 |
Correct |
108 ms |
22056 KB |
ok, correct split |
9 |
Correct |
119 ms |
21368 KB |
ok, correct split |
10 |
Correct |
110 ms |
24696 KB |
ok, correct split |
11 |
Correct |
121 ms |
24696 KB |
ok, correct split |
12 |
Correct |
7 ms |
5120 KB |
ok, correct split |
13 |
Correct |
7 ms |
4992 KB |
ok, correct split |
14 |
Correct |
7 ms |
4992 KB |
ok, correct split |
15 |
Correct |
124 ms |
21112 KB |
ok, correct split |
16 |
Correct |
99 ms |
15480 KB |
ok, correct split |
17 |
Correct |
108 ms |
24696 KB |
ok, correct split |
18 |
Correct |
116 ms |
21880 KB |
ok, correct split |
19 |
Correct |
147 ms |
19064 KB |
ok, correct split |
20 |
Correct |
105 ms |
16888 KB |
ok, correct split |
21 |
Correct |
63 ms |
14192 KB |
ok, correct split |
22 |
Correct |
62 ms |
14192 KB |
ok, correct split |
23 |
Correct |
64 ms |
14576 KB |
ok, correct split |
24 |
Correct |
7 ms |
4992 KB |
ok, correct split |
25 |
Correct |
104 ms |
15480 KB |
ok, correct split |
26 |
Correct |
36 ms |
9208 KB |
ok, correct split |
27 |
Correct |
7 ms |
5096 KB |
ok, correct split |
28 |
Correct |
115 ms |
19448 KB |
ok, correct split |
29 |
Correct |
124 ms |
19324 KB |
ok, correct split |
30 |
Correct |
119 ms |
19064 KB |
ok, correct split |
31 |
Correct |
116 ms |
20344 KB |
ok, correct split |
32 |
Correct |
124 ms |
18808 KB |
ok, correct split |
33 |
Correct |
31 ms |
8440 KB |
ok, no valid answer |
34 |
Correct |
44 ms |
10232 KB |
ok, no valid answer |
35 |
Correct |
77 ms |
14836 KB |
ok, no valid answer |
36 |
Correct |
96 ms |
15352 KB |
ok, no valid answer |
37 |
Correct |
62 ms |
14704 KB |
ok, no valid answer |
38 |
Correct |
7 ms |
4992 KB |
ok, correct split |
39 |
Correct |
7 ms |
4992 KB |
ok, no valid answer |
40 |
Correct |
7 ms |
5024 KB |
ok, correct split |
41 |
Correct |
7 ms |
4992 KB |
ok, correct split |
42 |
Correct |
7 ms |
4992 KB |
ok, correct split |
43 |
Correct |
7 ms |
4992 KB |
ok, correct split |
44 |
Correct |
7 ms |
4992 KB |
ok, correct split |
45 |
Correct |
7 ms |
4992 KB |
ok, correct split |
46 |
Correct |
10 ms |
5376 KB |
ok, correct split |
47 |
Correct |
9 ms |
5376 KB |
ok, correct split |
48 |
Correct |
7 ms |
5120 KB |
ok, correct split |
49 |
Correct |
9 ms |
5376 KB |
ok, correct split |
50 |
Correct |
7 ms |
4992 KB |
ok, correct split |
51 |
Correct |
7 ms |
4992 KB |
ok, correct split |
52 |
Correct |
7 ms |
4992 KB |
ok, correct split |
53 |
Correct |
7 ms |
4992 KB |
ok, correct split |
54 |
Correct |
7 ms |
4992 KB |
ok, correct split |
55 |
Correct |
7 ms |
4992 KB |
ok, correct split |
56 |
Correct |
7 ms |
5120 KB |
ok, correct split |
57 |
Correct |
10 ms |
5376 KB |
ok, correct split |
58 |
Correct |
9 ms |
5504 KB |
ok, correct split |
59 |
Correct |
9 ms |
5376 KB |
ok, correct split |
60 |
Correct |
9 ms |
5504 KB |
ok, correct split |
61 |
Correct |
9 ms |
5504 KB |
ok, correct split |
62 |
Correct |
9 ms |
5376 KB |
ok, correct split |
63 |
Incorrect |
11 ms |
5376 KB |
jury found a solution, contestant did not |
64 |
Halted |
0 ms |
0 KB |
- |