#include "split.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MAXN = 100005;
int N, M, sz[MAXN], parent[MAXN], nodes, nodeA, vis[MAXN], vis2[MAXN], centroid;
vi Tree[MAXN], Graph[MAXN], ans, nodes2;
vector < pii > part ( 3, {0, 0} );
map<pii, int> MP;
int pre ( int node, int p = -1 )
{
sz[node] = 1;
for ( auto i : Tree[node] )
if ( i != p )
sz[node] += pre ( i, node );
return sz[node];
}
int find_centroid ( int node, int p = -1 )
{
for ( auto i : Tree[node] )
if ( i != p && sz[i] > sz[0] / 2 )
return find_centroid ( i, node );
return node;
}
int look ( int node )
{
if ( node == parent[node] )
return node;
return parent[node] = look ( parent[node] );
}
void join ( int nodeA, int nodeB )
{
parent[look(nodeB)] = look(nodeA);
}
void dfs ( int root, int node, int p = -1 )
{
join ( root, node );
for ( auto i : Tree[node] )
if ( i != p )
dfs ( root, i, node );
}
void paint ( int node, int p, int color )
{
if ( nodes )
ans[node] = color, nodes--;
else
ans[node] = part[2].second;
for ( auto i : Tree[node] )
if ( i != p && !vis[i] )
paint ( i, node, color );
}
bool possible ( int node )
{
if ( nodes )
nodes -= sz[node];
vis[node] = 1;
for ( auto i : Graph[node] )
if ( !vis[i] && possible ( i ) )
return 1;
return 0;
}
void paint2 ( int node, int color )
{
if ( nodes > 0 )
{
paint ( node, centroid, color );
vis[node] = 1;
}
else
{
return;
}
vis2[node] = 1;
for ( auto i : Graph[node] )
if ( !vis2[i] )
paint2 ( i, color );
}
vi find_split ( int _n, int a, int b, int c, vi p, vi q )
{
part[0] = {a, 1};
part[1] = {b, 2};
part[2] = {c, 3};
sort ( part.begin(), part.end() );
N = _n;
M = p.size();
ans.resize ( N );
for ( int i = 0; i < N; i++ )
parent[i] = i, ans[i] = 0;
for ( int i = 0; i < M; i++ )
{
if ( look ( p[i] ) != look ( q[i] ) )
{
join ( p[i], q[i] );
Tree[p[i]].push_back ( q[i] );
Tree[q[i]].push_back ( p[i] );
}
}
pre ( 0 );
centroid = find_centroid ( 0 );
pre ( centroid );
for ( int i = 0; i < N; i++ )
parent[i] = i;
nodeA = -1;
for ( auto i : Tree[centroid] )
{
dfs ( i, i, centroid );
if ( sz[i] >= part[0].first )
nodeA = i;
nodes2.push_back ( i );
}
if ( nodeA != -1 )
{
nodes = part[0].first;
paint ( nodeA, centroid, part[0].second );
vis[nodeA] = 1;
nodes = part[1].first;
paint ( centroid, -1, part[1].second );
return ans;
}
for ( int i = 0; i < M; i++ )
{
if ( p[i] == centroid or q[i] == centroid )
continue;
if ( look(p[i]) != look(q[i]) && !MP[{look(p[i]), look(q[i])}])
{
Graph[look(p[i])].push_back ( look(q[i]) );
Graph[look(q[i])].push_back ( look(p[i]) );
MP[{look(p[i]), look(q[i])}] = 1;
MP[{look(q[i]), look(p[i])}] = 1;
}
}
for ( auto i : nodes2 )
{
if ( vis[i] )
continue;
nodes = part[0].first;
possible ( i );
if ( nodes <= 0 )
{
for ( auto j : nodes2 )
vis[j] = 0;
nodes = part[0].first;
paint2 ( i, part[0].second );
nodes = part[1].first;
paint ( centroid, -1, part[1].second );
return ans;
}
}
for ( auto &i : ans )
i = 0;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
ok, correct split |
2 |
Correct |
7 ms |
4984 KB |
ok, correct split |
3 |
Correct |
6 ms |
4984 KB |
ok, correct split |
4 |
Correct |
6 ms |
4984 KB |
ok, correct split |
5 |
Correct |
6 ms |
4984 KB |
ok, correct split |
6 |
Correct |
6 ms |
4984 KB |
ok, correct split |
7 |
Correct |
123 ms |
15736 KB |
ok, correct split |
8 |
Correct |
117 ms |
14456 KB |
ok, correct split |
9 |
Correct |
142 ms |
13948 KB |
ok, correct split |
10 |
Correct |
132 ms |
15864 KB |
ok, correct split |
11 |
Correct |
135 ms |
15096 KB |
ok, correct split |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
ok, correct split |
2 |
Correct |
7 ms |
4984 KB |
ok, correct split |
3 |
Correct |
6 ms |
4984 KB |
ok, correct split |
4 |
Correct |
151 ms |
12280 KB |
ok, correct split |
5 |
Correct |
99 ms |
11384 KB |
ok, correct split |
6 |
Correct |
127 ms |
15832 KB |
ok, correct split |
7 |
Correct |
122 ms |
14328 KB |
ok, correct split |
8 |
Correct |
141 ms |
12764 KB |
ok, correct split |
9 |
Correct |
155 ms |
11256 KB |
ok, correct split |
10 |
Correct |
73 ms |
12400 KB |
ok, correct split |
11 |
Correct |
73 ms |
12244 KB |
ok, correct split |
12 |
Correct |
77 ms |
12280 KB |
ok, correct split |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
ok, correct split |
2 |
Correct |
108 ms |
11456 KB |
ok, correct split |
3 |
Correct |
42 ms |
7544 KB |
ok, correct split |
4 |
Correct |
7 ms |
4856 KB |
ok, correct split |
5 |
Correct |
124 ms |
12928 KB |
ok, correct split |
6 |
Correct |
108 ms |
12664 KB |
ok, correct split |
7 |
Correct |
132 ms |
12664 KB |
ok, correct split |
8 |
Correct |
127 ms |
13432 KB |
ok, correct split |
9 |
Correct |
126 ms |
12768 KB |
ok, correct split |
10 |
Correct |
33 ms |
7288 KB |
ok, no valid answer |
11 |
Correct |
48 ms |
8440 KB |
ok, no valid answer |
12 |
Correct |
87 ms |
12552 KB |
ok, no valid answer |
13 |
Correct |
95 ms |
11896 KB |
ok, no valid answer |
14 |
Correct |
75 ms |
12656 KB |
ok, no valid answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
ok, correct split |
2 |
Correct |
6 ms |
4984 KB |
ok, no valid answer |
3 |
Correct |
6 ms |
4988 KB |
ok, correct split |
4 |
Correct |
6 ms |
5112 KB |
ok, correct split |
5 |
Correct |
6 ms |
4984 KB |
ok, correct split |
6 |
Correct |
7 ms |
5112 KB |
ok, correct split |
7 |
Correct |
6 ms |
5112 KB |
ok, correct split |
8 |
Correct |
6 ms |
4984 KB |
ok, correct split |
9 |
Correct |
8 ms |
5240 KB |
ok, correct split |
10 |
Correct |
8 ms |
5240 KB |
ok, correct split |
11 |
Correct |
6 ms |
5116 KB |
ok, correct split |
12 |
Correct |
9 ms |
5372 KB |
ok, correct split |
13 |
Correct |
6 ms |
4984 KB |
ok, correct split |
14 |
Correct |
6 ms |
4984 KB |
ok, correct split |
15 |
Correct |
6 ms |
5112 KB |
ok, correct split |
16 |
Correct |
6 ms |
4984 KB |
ok, correct split |
17 |
Correct |
6 ms |
4984 KB |
ok, correct split |
18 |
Correct |
6 ms |
4984 KB |
ok, correct split |
19 |
Correct |
6 ms |
5112 KB |
ok, correct split |
20 |
Correct |
6 ms |
5112 KB |
ok, correct split |
21 |
Correct |
8 ms |
5240 KB |
ok, correct split |
22 |
Correct |
7 ms |
5240 KB |
ok, correct split |
23 |
Correct |
8 ms |
5240 KB |
ok, correct split |
24 |
Correct |
9 ms |
5240 KB |
ok, correct split |
25 |
Correct |
8 ms |
5240 KB |
ok, correct split |
26 |
Correct |
8 ms |
5240 KB |
ok, correct split |
27 |
Correct |
8 ms |
5240 KB |
ok, correct split |
28 |
Correct |
8 ms |
5240 KB |
ok, correct split |
29 |
Correct |
6 ms |
5112 KB |
ok, correct split |
30 |
Correct |
8 ms |
5240 KB |
ok, correct split |
31 |
Correct |
6 ms |
5112 KB |
ok, correct split |
32 |
Correct |
6 ms |
4984 KB |
ok, correct split |
33 |
Correct |
6 ms |
4984 KB |
ok, correct split |
34 |
Correct |
8 ms |
5244 KB |
ok, correct split |
35 |
Correct |
8 ms |
5240 KB |
ok, correct split |
36 |
Correct |
8 ms |
5240 KB |
ok, correct split |
37 |
Correct |
10 ms |
5496 KB |
ok, correct split |
38 |
Correct |
10 ms |
5496 KB |
ok, correct split |
39 |
Correct |
10 ms |
5496 KB |
ok, correct split |
40 |
Correct |
10 ms |
5496 KB |
ok, correct split |
41 |
Correct |
8 ms |
5240 KB |
ok, correct split |
42 |
Incorrect |
8 ms |
5244 KB |
2 components are not connected |
43 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
ok, correct split |
2 |
Correct |
7 ms |
4984 KB |
ok, correct split |
3 |
Correct |
6 ms |
4984 KB |
ok, correct split |
4 |
Correct |
6 ms |
4984 KB |
ok, correct split |
5 |
Correct |
6 ms |
4984 KB |
ok, correct split |
6 |
Correct |
6 ms |
4984 KB |
ok, correct split |
7 |
Correct |
123 ms |
15736 KB |
ok, correct split |
8 |
Correct |
117 ms |
14456 KB |
ok, correct split |
9 |
Correct |
142 ms |
13948 KB |
ok, correct split |
10 |
Correct |
132 ms |
15864 KB |
ok, correct split |
11 |
Correct |
135 ms |
15096 KB |
ok, correct split |
12 |
Correct |
6 ms |
5112 KB |
ok, correct split |
13 |
Correct |
7 ms |
4984 KB |
ok, correct split |
14 |
Correct |
6 ms |
4984 KB |
ok, correct split |
15 |
Correct |
151 ms |
12280 KB |
ok, correct split |
16 |
Correct |
99 ms |
11384 KB |
ok, correct split |
17 |
Correct |
127 ms |
15832 KB |
ok, correct split |
18 |
Correct |
122 ms |
14328 KB |
ok, correct split |
19 |
Correct |
141 ms |
12764 KB |
ok, correct split |
20 |
Correct |
155 ms |
11256 KB |
ok, correct split |
21 |
Correct |
73 ms |
12400 KB |
ok, correct split |
22 |
Correct |
73 ms |
12244 KB |
ok, correct split |
23 |
Correct |
77 ms |
12280 KB |
ok, correct split |
24 |
Correct |
6 ms |
4984 KB |
ok, correct split |
25 |
Correct |
108 ms |
11456 KB |
ok, correct split |
26 |
Correct |
42 ms |
7544 KB |
ok, correct split |
27 |
Correct |
7 ms |
4856 KB |
ok, correct split |
28 |
Correct |
124 ms |
12928 KB |
ok, correct split |
29 |
Correct |
108 ms |
12664 KB |
ok, correct split |
30 |
Correct |
132 ms |
12664 KB |
ok, correct split |
31 |
Correct |
127 ms |
13432 KB |
ok, correct split |
32 |
Correct |
126 ms |
12768 KB |
ok, correct split |
33 |
Correct |
33 ms |
7288 KB |
ok, no valid answer |
34 |
Correct |
48 ms |
8440 KB |
ok, no valid answer |
35 |
Correct |
87 ms |
12552 KB |
ok, no valid answer |
36 |
Correct |
95 ms |
11896 KB |
ok, no valid answer |
37 |
Correct |
75 ms |
12656 KB |
ok, no valid answer |
38 |
Correct |
6 ms |
4984 KB |
ok, correct split |
39 |
Correct |
6 ms |
4984 KB |
ok, no valid answer |
40 |
Correct |
6 ms |
4988 KB |
ok, correct split |
41 |
Correct |
6 ms |
5112 KB |
ok, correct split |
42 |
Correct |
6 ms |
4984 KB |
ok, correct split |
43 |
Correct |
7 ms |
5112 KB |
ok, correct split |
44 |
Correct |
6 ms |
5112 KB |
ok, correct split |
45 |
Correct |
6 ms |
4984 KB |
ok, correct split |
46 |
Correct |
8 ms |
5240 KB |
ok, correct split |
47 |
Correct |
8 ms |
5240 KB |
ok, correct split |
48 |
Correct |
6 ms |
5116 KB |
ok, correct split |
49 |
Correct |
9 ms |
5372 KB |
ok, correct split |
50 |
Correct |
6 ms |
4984 KB |
ok, correct split |
51 |
Correct |
6 ms |
4984 KB |
ok, correct split |
52 |
Correct |
6 ms |
5112 KB |
ok, correct split |
53 |
Correct |
6 ms |
4984 KB |
ok, correct split |
54 |
Correct |
6 ms |
4984 KB |
ok, correct split |
55 |
Correct |
6 ms |
4984 KB |
ok, correct split |
56 |
Correct |
6 ms |
5112 KB |
ok, correct split |
57 |
Correct |
6 ms |
5112 KB |
ok, correct split |
58 |
Correct |
8 ms |
5240 KB |
ok, correct split |
59 |
Correct |
7 ms |
5240 KB |
ok, correct split |
60 |
Correct |
8 ms |
5240 KB |
ok, correct split |
61 |
Correct |
9 ms |
5240 KB |
ok, correct split |
62 |
Correct |
8 ms |
5240 KB |
ok, correct split |
63 |
Correct |
8 ms |
5240 KB |
ok, correct split |
64 |
Correct |
8 ms |
5240 KB |
ok, correct split |
65 |
Correct |
8 ms |
5240 KB |
ok, correct split |
66 |
Correct |
6 ms |
5112 KB |
ok, correct split |
67 |
Correct |
8 ms |
5240 KB |
ok, correct split |
68 |
Correct |
6 ms |
5112 KB |
ok, correct split |
69 |
Correct |
6 ms |
4984 KB |
ok, correct split |
70 |
Correct |
6 ms |
4984 KB |
ok, correct split |
71 |
Correct |
8 ms |
5244 KB |
ok, correct split |
72 |
Correct |
8 ms |
5240 KB |
ok, correct split |
73 |
Correct |
8 ms |
5240 KB |
ok, correct split |
74 |
Correct |
10 ms |
5496 KB |
ok, correct split |
75 |
Correct |
10 ms |
5496 KB |
ok, correct split |
76 |
Correct |
10 ms |
5496 KB |
ok, correct split |
77 |
Correct |
10 ms |
5496 KB |
ok, correct split |
78 |
Correct |
8 ms |
5240 KB |
ok, correct split |
79 |
Incorrect |
8 ms |
5244 KB |
2 components are not connected |
80 |
Halted |
0 ms |
0 KB |
- |