#include "split.h"
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
//#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
using namespace std;
const int maxn = 2e5 + 10;
vi adj[maxn], tree[maxn], oth[maxn];
vi g[maxn];
int num[3], ans[maxn], sz[maxn], comp[maxn];
bool mark[maxn];
void dfs(int v){
mark[v] = 1;
for(auto u : adj[v]){
if(!mark[u]){
tree[v].push_back(u);
tree[u].push_back(v);
dfs(u);
}
else{
oth[u].push_back(v);
oth[v].push_back(u);
}
}
}
bool markTree[maxn];
void dfs_tree(int v,int root){
sz[v] = 1;
if(v == root){
memset(markTree, 0, sizeof markTree);
comp[v] = -1;
}
if(markTree[v])
return;
markTree[v] = 1;
for(auto u : tree[v]){
if(markTree[u])
continue;
if(v == root)
comp[u] = u;
else
comp[u] = comp[v];
dfs_tree(u, root);
sz[v] += sz[u];
}
}
int Rem;
void dfs_g(int v){
if(mark[v] || Rem <= 0)
return;
mark[v] = 1;
Rem -= sz[v];
if(Rem <= 0) return;
for(auto u : g[v])
dfs_g(u);
}
int answer[maxn];
int rems = 0;
vi seen;
void dfs_ok(int v,int col){
if(mark[v] || ans[v] != col || rems <= 0)
return;
rems--;
answer[v] = col;
mark[v] = 1;
if(col == 2)
seen.push_back(v);
for(auto u : adj[v])
dfs_ok(u, col);
}
void make_ok(int n,int root){
for(int i=0; i<n; i++)
answer[i] = 3;
rems = num[0];
memset(mark, 0, sizeof mark);
for(int i=0; i<n; i++)
if(ans[i] == 1){
dfs_ok(i, 1);
break;
}
rems = num[1];
memset(mark, 0, sizeof mark);
dfs_ok(root, 2);
}
vector<int> find_split(int n, int a1, int b1, int c1, vector<int> from, vector<int> to) {
int m = from.size();
num[0] = a1, num[1] = b1, num[2] = c1;
sort(num, num + 3);
for(int i=0; i<m; i++){
int u = from[i], v = to[i];
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(0);
dfs_tree(0, 0);
int root = 0;
while(1){
int bef = root;
for(auto u : tree[root]){
if(sz[u] > n/2 && sz[u] < sz[root])
root = u;
}
if(bef == root)
break;
}
memset(sz, 0, sizeof sz);
dfs_tree(root, root);
bool can = true;
if(m == n - 1){
can = false;
for(auto u : tree[root]){
if(sz[u] >= num[0]){
for(int i=0; i<n; i++)
ans[i] = (comp[i] == u ? 1 : 2);
can = true;
break;
}
}
make_ok(n, root);
}
else{
for(int i=0; i<n; i++){
for(auto j : oth[i]){
if(j != root && i != root){
int u = comp[i];
int v = comp[j];
if(u != v){
g[u].push_back(v);
}
}
}
}
can = false;
for(auto u : tree[root]){
if(sz[u] >= num[0]){
for(int i=0; i<n; i++)
ans[i] = (comp[i] == u ? 1 : 2);
can = true;
break;
}
}
if(!can){
Rem = num[0];
can = true;
memset(mark, 0, sizeof mark);
for(auto u : tree[root])
dfs_g(u);
if(Rem > 0)
can = false;
for(int i=0; i<n; i++){
if(i != root && mark[comp[i]])
ans[i] = 1;
else
ans[i] = 2;
}
}
make_ok(n, root);
}/*
cout << "CAN" << can << endl;
for(int i=0; i<n; i++)
cout << answer[i] << " ";
cout << endl;*/
pii per[3];
per[0] = {a1, 1};
per[1] = {b1, 2};
per[2] = {c1, 3};
sort(per, per + 3);
vi res;
res.resize(n);
if(can){
for(int i=0; i<n; i++)
res[i] = per[answer[i] - 1].Y;
}
return res;
}
/*
int main(){
int n, m;
cin >> n >> m;
int a1, b1, c1;
cin >> a1 >> b1 >> c1;
vi fr, to;
for(int i=0; i<m; i++){
int x, y;
cin >> x >> y;
fr.push_back(x);
to.push_back(y);
}
vi res = find_split(n, a1, b1, c1, fr, to);
for(auto t : res)
cout << t << " ";
cout << endl;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
20216 KB |
ok, correct split |
2 |
Correct |
20 ms |
20216 KB |
ok, correct split |
3 |
Correct |
20 ms |
20216 KB |
ok, correct split |
4 |
Correct |
20 ms |
20216 KB |
ok, correct split |
5 |
Correct |
20 ms |
20344 KB |
ok, correct split |
6 |
Correct |
21 ms |
20316 KB |
ok, correct split |
7 |
Correct |
245 ms |
39004 KB |
ok, correct split |
8 |
Correct |
233 ms |
36964 KB |
ok, correct split |
9 |
Correct |
239 ms |
36696 KB |
ok, correct split |
10 |
Correct |
234 ms |
39044 KB |
ok, correct split |
11 |
Correct |
243 ms |
39284 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
20344 KB |
ok, correct split |
2 |
Correct |
20 ms |
20316 KB |
ok, correct split |
3 |
Correct |
21 ms |
20216 KB |
ok, correct split |
4 |
Correct |
270 ms |
38200 KB |
ok, correct split |
5 |
Correct |
191 ms |
33528 KB |
ok, correct split |
6 |
Correct |
328 ms |
39100 KB |
ok, correct split |
7 |
Correct |
332 ms |
37172 KB |
ok, correct split |
8 |
Correct |
290 ms |
36584 KB |
ok, correct split |
9 |
Correct |
215 ms |
33268 KB |
ok, correct split |
10 |
Correct |
157 ms |
34540 KB |
ok, correct split |
11 |
Correct |
245 ms |
34544 KB |
ok, correct split |
12 |
Correct |
155 ms |
34416 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
20344 KB |
ok, correct split |
2 |
Correct |
245 ms |
33428 KB |
ok, correct split |
3 |
Correct |
71 ms |
25464 KB |
ok, correct split |
4 |
Correct |
20 ms |
20344 KB |
ok, correct split |
5 |
Correct |
232 ms |
35316 KB |
ok, correct split |
6 |
Correct |
231 ms |
34932 KB |
ok, correct split |
7 |
Correct |
235 ms |
35060 KB |
ok, correct split |
8 |
Correct |
280 ms |
36052 KB |
ok, correct split |
9 |
Correct |
229 ms |
35060 KB |
ok, correct split |
10 |
Correct |
63 ms |
24440 KB |
ok, no valid answer |
11 |
Correct |
120 ms |
26488 KB |
ok, no valid answer |
12 |
Correct |
214 ms |
33268 KB |
ok, no valid answer |
13 |
Correct |
226 ms |
32888 KB |
ok, no valid answer |
14 |
Correct |
169 ms |
33648 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
20312 KB |
ok, correct split |
2 |
Correct |
22 ms |
20472 KB |
ok, no valid answer |
3 |
Correct |
21 ms |
20316 KB |
ok, correct split |
4 |
Correct |
19 ms |
20344 KB |
ok, correct split |
5 |
Correct |
21 ms |
20344 KB |
ok, correct split |
6 |
Correct |
21 ms |
20344 KB |
ok, correct split |
7 |
Correct |
21 ms |
20216 KB |
ok, correct split |
8 |
Correct |
21 ms |
20216 KB |
ok, correct split |
9 |
Correct |
25 ms |
20732 KB |
ok, correct split |
10 |
Correct |
24 ms |
20728 KB |
ok, correct split |
11 |
Correct |
20 ms |
20344 KB |
ok, correct split |
12 |
Correct |
24 ms |
20728 KB |
ok, correct split |
13 |
Correct |
21 ms |
20216 KB |
ok, correct split |
14 |
Correct |
21 ms |
20344 KB |
ok, correct split |
15 |
Correct |
21 ms |
20216 KB |
ok, correct split |
16 |
Correct |
21 ms |
20216 KB |
ok, correct split |
17 |
Correct |
21 ms |
20344 KB |
ok, correct split |
18 |
Correct |
21 ms |
20216 KB |
ok, correct split |
19 |
Correct |
21 ms |
20344 KB |
ok, correct split |
20 |
Correct |
27 ms |
20472 KB |
ok, correct split |
21 |
Correct |
22 ms |
20600 KB |
ok, correct split |
22 |
Correct |
23 ms |
20728 KB |
ok, correct split |
23 |
Correct |
23 ms |
20728 KB |
ok, correct split |
24 |
Correct |
23 ms |
20700 KB |
ok, correct split |
25 |
Correct |
24 ms |
20600 KB |
ok, correct split |
26 |
Correct |
24 ms |
20860 KB |
ok, correct split |
27 |
Correct |
24 ms |
20856 KB |
ok, correct split |
28 |
Correct |
28 ms |
20728 KB |
ok, correct split |
29 |
Correct |
25 ms |
20344 KB |
ok, correct split |
30 |
Correct |
29 ms |
20816 KB |
ok, correct split |
31 |
Correct |
26 ms |
20472 KB |
ok, correct split |
32 |
Correct |
25 ms |
20292 KB |
ok, correct split |
33 |
Correct |
21 ms |
20344 KB |
ok, correct split |
34 |
Correct |
25 ms |
20728 KB |
ok, correct split |
35 |
Correct |
24 ms |
20600 KB |
ok, correct split |
36 |
Correct |
23 ms |
20644 KB |
ok, correct split |
37 |
Correct |
24 ms |
20728 KB |
ok, correct split |
38 |
Correct |
24 ms |
20728 KB |
ok, correct split |
39 |
Correct |
25 ms |
20780 KB |
ok, correct split |
40 |
Correct |
25 ms |
20728 KB |
ok, correct split |
41 |
Correct |
23 ms |
20472 KB |
ok, correct split |
42 |
Correct |
23 ms |
20472 KB |
ok, correct split |
43 |
Correct |
25 ms |
20856 KB |
ok, correct split |
44 |
Correct |
24 ms |
20856 KB |
ok, correct split |
45 |
Correct |
24 ms |
20728 KB |
ok, correct split |
46 |
Correct |
24 ms |
20600 KB |
ok, correct split |
47 |
Incorrect |
23 ms |
20600 KB |
invalid split: #1=600, #2=800, #3=1000 |
48 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
20216 KB |
ok, correct split |
2 |
Correct |
20 ms |
20216 KB |
ok, correct split |
3 |
Correct |
20 ms |
20216 KB |
ok, correct split |
4 |
Correct |
20 ms |
20216 KB |
ok, correct split |
5 |
Correct |
20 ms |
20344 KB |
ok, correct split |
6 |
Correct |
21 ms |
20316 KB |
ok, correct split |
7 |
Correct |
245 ms |
39004 KB |
ok, correct split |
8 |
Correct |
233 ms |
36964 KB |
ok, correct split |
9 |
Correct |
239 ms |
36696 KB |
ok, correct split |
10 |
Correct |
234 ms |
39044 KB |
ok, correct split |
11 |
Correct |
243 ms |
39284 KB |
ok, correct split |
12 |
Correct |
20 ms |
20344 KB |
ok, correct split |
13 |
Correct |
20 ms |
20316 KB |
ok, correct split |
14 |
Correct |
21 ms |
20216 KB |
ok, correct split |
15 |
Correct |
270 ms |
38200 KB |
ok, correct split |
16 |
Correct |
191 ms |
33528 KB |
ok, correct split |
17 |
Correct |
328 ms |
39100 KB |
ok, correct split |
18 |
Correct |
332 ms |
37172 KB |
ok, correct split |
19 |
Correct |
290 ms |
36584 KB |
ok, correct split |
20 |
Correct |
215 ms |
33268 KB |
ok, correct split |
21 |
Correct |
157 ms |
34540 KB |
ok, correct split |
22 |
Correct |
245 ms |
34544 KB |
ok, correct split |
23 |
Correct |
155 ms |
34416 KB |
ok, correct split |
24 |
Correct |
20 ms |
20344 KB |
ok, correct split |
25 |
Correct |
245 ms |
33428 KB |
ok, correct split |
26 |
Correct |
71 ms |
25464 KB |
ok, correct split |
27 |
Correct |
20 ms |
20344 KB |
ok, correct split |
28 |
Correct |
232 ms |
35316 KB |
ok, correct split |
29 |
Correct |
231 ms |
34932 KB |
ok, correct split |
30 |
Correct |
235 ms |
35060 KB |
ok, correct split |
31 |
Correct |
280 ms |
36052 KB |
ok, correct split |
32 |
Correct |
229 ms |
35060 KB |
ok, correct split |
33 |
Correct |
63 ms |
24440 KB |
ok, no valid answer |
34 |
Correct |
120 ms |
26488 KB |
ok, no valid answer |
35 |
Correct |
214 ms |
33268 KB |
ok, no valid answer |
36 |
Correct |
226 ms |
32888 KB |
ok, no valid answer |
37 |
Correct |
169 ms |
33648 KB |
ok, no valid answer |
38 |
Correct |
25 ms |
20312 KB |
ok, correct split |
39 |
Correct |
22 ms |
20472 KB |
ok, no valid answer |
40 |
Correct |
21 ms |
20316 KB |
ok, correct split |
41 |
Correct |
19 ms |
20344 KB |
ok, correct split |
42 |
Correct |
21 ms |
20344 KB |
ok, correct split |
43 |
Correct |
21 ms |
20344 KB |
ok, correct split |
44 |
Correct |
21 ms |
20216 KB |
ok, correct split |
45 |
Correct |
21 ms |
20216 KB |
ok, correct split |
46 |
Correct |
25 ms |
20732 KB |
ok, correct split |
47 |
Correct |
24 ms |
20728 KB |
ok, correct split |
48 |
Correct |
20 ms |
20344 KB |
ok, correct split |
49 |
Correct |
24 ms |
20728 KB |
ok, correct split |
50 |
Correct |
21 ms |
20216 KB |
ok, correct split |
51 |
Correct |
21 ms |
20344 KB |
ok, correct split |
52 |
Correct |
21 ms |
20216 KB |
ok, correct split |
53 |
Correct |
21 ms |
20216 KB |
ok, correct split |
54 |
Correct |
21 ms |
20344 KB |
ok, correct split |
55 |
Correct |
21 ms |
20216 KB |
ok, correct split |
56 |
Correct |
21 ms |
20344 KB |
ok, correct split |
57 |
Correct |
27 ms |
20472 KB |
ok, correct split |
58 |
Correct |
22 ms |
20600 KB |
ok, correct split |
59 |
Correct |
23 ms |
20728 KB |
ok, correct split |
60 |
Correct |
23 ms |
20728 KB |
ok, correct split |
61 |
Correct |
23 ms |
20700 KB |
ok, correct split |
62 |
Correct |
24 ms |
20600 KB |
ok, correct split |
63 |
Correct |
24 ms |
20860 KB |
ok, correct split |
64 |
Correct |
24 ms |
20856 KB |
ok, correct split |
65 |
Correct |
28 ms |
20728 KB |
ok, correct split |
66 |
Correct |
25 ms |
20344 KB |
ok, correct split |
67 |
Correct |
29 ms |
20816 KB |
ok, correct split |
68 |
Correct |
26 ms |
20472 KB |
ok, correct split |
69 |
Correct |
25 ms |
20292 KB |
ok, correct split |
70 |
Correct |
21 ms |
20344 KB |
ok, correct split |
71 |
Correct |
25 ms |
20728 KB |
ok, correct split |
72 |
Correct |
24 ms |
20600 KB |
ok, correct split |
73 |
Correct |
23 ms |
20644 KB |
ok, correct split |
74 |
Correct |
24 ms |
20728 KB |
ok, correct split |
75 |
Correct |
24 ms |
20728 KB |
ok, correct split |
76 |
Correct |
25 ms |
20780 KB |
ok, correct split |
77 |
Correct |
25 ms |
20728 KB |
ok, correct split |
78 |
Correct |
23 ms |
20472 KB |
ok, correct split |
79 |
Correct |
23 ms |
20472 KB |
ok, correct split |
80 |
Correct |
25 ms |
20856 KB |
ok, correct split |
81 |
Correct |
24 ms |
20856 KB |
ok, correct split |
82 |
Correct |
24 ms |
20728 KB |
ok, correct split |
83 |
Correct |
24 ms |
20600 KB |
ok, correct split |
84 |
Incorrect |
23 ms |
20600 KB |
invalid split: #1=600, #2=800, #3=1000 |
85 |
Halted |
0 ms |
0 KB |
- |