#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;
bool mrk[N];
int siz[N], mem, pr[N], col, A[3], C[3];
void dfs(int v){
if (mrk[v]) return;
mrk[v] = 1;
vc.PB(v);
for (int u : g[v])
dfs(u);
}
void build_sz(int v, int p){
siz[v] = 1;
pr[v] = p;
for (int u : g[v]){
if (u == p) continue;
build_sz(u, v);
siz[v] += siz[u];
}
}
void fill(int v, int p){
if (mem == 0) return;
mem--;
res[v] = col;
for (int u : g[v]){
if (u == p) continue;
fill(u, v);
}
}
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]);
}
if (sz(p) == n - 1){
build_sz(0, -1);
A[0] = a; A[1] = b; A[2] = c;
C[0] = 1; C[1] = 2; C[2] = 3;
for (int v = 0; v < n; v++){
int sub = siz[v], up = n - siz[v];
bool was = 0;
for (int i = 0; i < 3 && !was; i++)
for (int j = 0; j < 3 && !was; j++)
if (i != j && A[i] <= sub && A[j] <= up){
was = 1;
mem = A[i]; col = C[i];
fill(v, pr[v]);
mem = A[j]; col = C[j];
fill(pr[v], v);
if (C[i] != 1 && C[j] != 1) col = 1;
if (C[i] != 2 && C[j] != 2) col = 2;
if (C[i] != 3 && C[j] != 3) col = 3;
for (int &cr : res)
if (cr == 0)
cr = col;
break;
}
if (was) break;
}
return res;
}
bool was = 0;
for (int i = 0; i < n; i++)
if (sz(g[i]) == 1){
was = 1;
dfs(i);
break;
}
if (!was) dfs(0);
for (int i = 0; i < a; i++)
res[vc[i]] = 1;
for (int i = 0; i < b; i++)
res[vc[a + i]] = 2;
for (int i = 0; i < c; i++)
res[vc[a + b + i]] = 3;
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
ok, correct split |
2 |
Correct |
7 ms |
2816 KB |
ok, correct split |
3 |
Correct |
6 ms |
2688 KB |
ok, correct split |
4 |
Correct |
6 ms |
2688 KB |
ok, correct split |
5 |
Correct |
6 ms |
2688 KB |
ok, correct split |
6 |
Correct |
6 ms |
2688 KB |
ok, correct split |
7 |
Correct |
85 ms |
15992 KB |
ok, correct split |
8 |
Correct |
79 ms |
14200 KB |
ok, correct split |
9 |
Correct |
86 ms |
13688 KB |
ok, correct split |
10 |
Correct |
82 ms |
14580 KB |
ok, correct split |
11 |
Correct |
82 ms |
14580 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
ok, correct split |
2 |
Correct |
6 ms |
2688 KB |
ok, correct split |
3 |
Correct |
6 ms |
2688 KB |
ok, correct split |
4 |
Correct |
102 ms |
13808 KB |
ok, correct split |
5 |
Correct |
71 ms |
10232 KB |
ok, correct split |
6 |
Correct |
78 ms |
14580 KB |
ok, correct split |
7 |
Correct |
99 ms |
14080 KB |
ok, correct split |
8 |
Correct |
113 ms |
13300 KB |
ok, correct split |
9 |
Correct |
74 ms |
9972 KB |
ok, correct split |
10 |
Correct |
54 ms |
10096 KB |
ok, correct split |
11 |
Correct |
57 ms |
10096 KB |
ok, correct split |
12 |
Correct |
63 ms |
10488 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
ok, correct split |
2 |
Correct |
75 ms |
10232 KB |
ok, correct split |
3 |
Correct |
30 ms |
5756 KB |
ok, correct split |
4 |
Correct |
6 ms |
2688 KB |
ok, correct split |
5 |
Correct |
108 ms |
12116 KB |
ok, correct split |
6 |
Correct |
89 ms |
12024 KB |
ok, correct split |
7 |
Correct |
87 ms |
11812 KB |
ok, correct split |
8 |
Correct |
90 ms |
12872 KB |
ok, correct split |
9 |
Correct |
92 ms |
11640 KB |
ok, correct split |
10 |
Correct |
26 ms |
5112 KB |
ok, no valid answer |
11 |
Correct |
36 ms |
6392 KB |
ok, no valid answer |
12 |
Correct |
64 ms |
10356 KB |
ok, no valid answer |
13 |
Correct |
74 ms |
10232 KB |
ok, no valid answer |
14 |
Correct |
77 ms |
10480 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2688 KB |
2 components are not connected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
ok, correct split |
2 |
Correct |
7 ms |
2816 KB |
ok, correct split |
3 |
Correct |
6 ms |
2688 KB |
ok, correct split |
4 |
Correct |
6 ms |
2688 KB |
ok, correct split |
5 |
Correct |
6 ms |
2688 KB |
ok, correct split |
6 |
Correct |
6 ms |
2688 KB |
ok, correct split |
7 |
Correct |
85 ms |
15992 KB |
ok, correct split |
8 |
Correct |
79 ms |
14200 KB |
ok, correct split |
9 |
Correct |
86 ms |
13688 KB |
ok, correct split |
10 |
Correct |
82 ms |
14580 KB |
ok, correct split |
11 |
Correct |
82 ms |
14580 KB |
ok, correct split |
12 |
Correct |
6 ms |
2688 KB |
ok, correct split |
13 |
Correct |
6 ms |
2688 KB |
ok, correct split |
14 |
Correct |
6 ms |
2688 KB |
ok, correct split |
15 |
Correct |
102 ms |
13808 KB |
ok, correct split |
16 |
Correct |
71 ms |
10232 KB |
ok, correct split |
17 |
Correct |
78 ms |
14580 KB |
ok, correct split |
18 |
Correct |
99 ms |
14080 KB |
ok, correct split |
19 |
Correct |
113 ms |
13300 KB |
ok, correct split |
20 |
Correct |
74 ms |
9972 KB |
ok, correct split |
21 |
Correct |
54 ms |
10096 KB |
ok, correct split |
22 |
Correct |
57 ms |
10096 KB |
ok, correct split |
23 |
Correct |
63 ms |
10488 KB |
ok, correct split |
24 |
Correct |
6 ms |
2688 KB |
ok, correct split |
25 |
Correct |
75 ms |
10232 KB |
ok, correct split |
26 |
Correct |
30 ms |
5756 KB |
ok, correct split |
27 |
Correct |
6 ms |
2688 KB |
ok, correct split |
28 |
Correct |
108 ms |
12116 KB |
ok, correct split |
29 |
Correct |
89 ms |
12024 KB |
ok, correct split |
30 |
Correct |
87 ms |
11812 KB |
ok, correct split |
31 |
Correct |
90 ms |
12872 KB |
ok, correct split |
32 |
Correct |
92 ms |
11640 KB |
ok, correct split |
33 |
Correct |
26 ms |
5112 KB |
ok, no valid answer |
34 |
Correct |
36 ms |
6392 KB |
ok, no valid answer |
35 |
Correct |
64 ms |
10356 KB |
ok, no valid answer |
36 |
Correct |
74 ms |
10232 KB |
ok, no valid answer |
37 |
Correct |
77 ms |
10480 KB |
ok, no valid answer |
38 |
Incorrect |
6 ms |
2688 KB |
2 components are not connected |
39 |
Halted |
0 ms |
0 KB |
- |