#include <bits/stdc++.h>
using namespace std;
int n;
int centroid;
const int N=100000;
vector<int> v[N];
vector<int> g[N];
vector<int> z[N];
vector<int> d;
vector<int> sub(N,0);
vector<int> id(N);
vector<bool> vis(N,0);
vector<int> res;
void dfs1(int a)
{
sub[a]=1;
for(int to:v[a])
{
if(sub[to]!=0) continue;
g[a].push_back(to);
g[to].push_back(a);
dfs1(to);
sub[a]+=sub[to];
}
}
int get_centroid(int a,int p=-1)
{
for(int to:g[a])
{
if(to!=p&&sub[to]>n/2) return get_centroid(to,a);
}
return a;
}
void dfs2(int a,int now)
{
sub[a]=1;
id[a]=now;
for(int to:g[a])
{
if(sub[to]!=0) continue;
if(now==-1) d.push_back(to);
dfs2(to,(now!=-1?now:to));
sub[a]+=sub[to];
}
}
void solve_one(vector<int> src,int num,int t)
{
vector<bool> pos(n,0);
for(int a:src) pos[a]=1;
queue<int> q;
q.push(src[0]);
res[src[0]]=t;
num--;
while(num>0)
{
int e=q.front();
q.pop();
for(int to:v[e])
{
if(to!=centroid&&pos[id[to]]==1&&res[to]==0)
{
q.push(to);
res[to]=t;
num--;
}
if(num==0) break;
}
}
}
void solve_two(int num,int t)
{
queue<int> q;
q.push(centroid);
while(num>0)
{
int e=q.front();
q.pop();
res[e]=t;
num--;
for(int to:g[e]) if(res[to]==0) q.push(to);
}
}
void solve_three(int t)
{
for(int i=0;i<n;i++) if(res[i]==0) res[i]=t;
}
vector<int> component(int src,int a)
{
vector<int> comp;
int cnt=0;
vis[src]=1;
queue<int> q;
q.push(src);
while(!q.empty())
{
int e=q.front();
q.pop();
cnt+=sub[e];
comp.push_back(e);
if(cnt>=a) break;
for(int to:z[e])
{
if(vis[to]) continue;
vis[to]=1;
q.push(to);
}
}
if(cnt>=a) return comp;
else return {-1};
}
vector<int> find_split(int _n,int a,int b,int c,vector<int> ca,vector<int> cb)
{
n=_n;
res.resize(n,0);
int m=ca.size();
for(int i=0;i<m;i++)
{
v[ca[i]].push_back(cb[i]);
v[cb[i]].push_back(ca[i]);
}
dfs1(0);
centroid=get_centroid(0);
for(int i=0;i<n;i++) sub[i]=0;
dfs2(centroid,-1);
vector<pair<int,int>> abc={{a,1},{b,2},{c,3}};
sort(abc.begin(),abc.end());
for(int i=0;i<m;i++)
{
if(ca[i]==centroid||cb[i]==centroid) continue;
if(id[ca[i]]!=id[cb[i]])
{
z[id[ca[i]]].push_back(id[cb[i]]);
z[id[cb[i]]].push_back(id[ca[i]]);
}
}
vector<pair<int,int>> p;
for(int to:d) p.push_back({sub[to],to});
sort(p.begin(),p.end(),greater<pair<int,int>>());
for(pair<int,int> pii:p)
{
int to=pii.second;
if(vis[to]) continue;
vector<int> comp=component(to,abc[0].first);
if(comp[0]==-1) continue;
solve_one(comp,abc[0].first,abc[0].second);
solve_two(abc[1].first,abc[1].second);
solve_three(abc[2].second);
return res;
}
return res;
}
/*int main()
{
int _n,_m;
scanf("%d%d",&_n,&_m);
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
vector<int> one,two;
for(int i=0;i<_m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
one.push_back(x);
two.push_back(y);
}
vector<int> temp=find_split(_n,a,b,c,one,two);
for(int a:temp) cout << a << " ";
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
ok, correct split |
2 |
Correct |
9 ms |
8184 KB |
ok, correct split |
3 |
Correct |
9 ms |
8184 KB |
ok, correct split |
4 |
Correct |
9 ms |
8184 KB |
ok, correct split |
5 |
Correct |
9 ms |
8220 KB |
ok, correct split |
6 |
Correct |
9 ms |
8184 KB |
ok, correct split |
7 |
Correct |
164 ms |
22876 KB |
ok, correct split |
8 |
Correct |
138 ms |
20984 KB |
ok, correct split |
9 |
Correct |
189 ms |
20344 KB |
ok, correct split |
10 |
Correct |
133 ms |
23032 KB |
ok, correct split |
11 |
Correct |
177 ms |
22992 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
ok, correct split |
2 |
Correct |
9 ms |
8184 KB |
ok, correct split |
3 |
Correct |
9 ms |
8188 KB |
ok, correct split |
4 |
Correct |
156 ms |
21028 KB |
ok, correct split |
5 |
Correct |
129 ms |
17016 KB |
ok, correct split |
6 |
Correct |
130 ms |
23032 KB |
ok, correct split |
7 |
Correct |
132 ms |
20804 KB |
ok, correct split |
8 |
Correct |
159 ms |
18936 KB |
ok, correct split |
9 |
Correct |
120 ms |
16888 KB |
ok, correct split |
10 |
Correct |
101 ms |
18772 KB |
ok, correct split |
11 |
Correct |
105 ms |
18900 KB |
ok, correct split |
12 |
Correct |
111 ms |
18816 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
ok, correct split |
2 |
Correct |
146 ms |
17016 KB |
ok, correct split |
3 |
Correct |
45 ms |
11768 KB |
ok, correct split |
4 |
Correct |
9 ms |
8312 KB |
ok, correct split |
5 |
Correct |
129 ms |
18952 KB |
ok, correct split |
6 |
Correct |
134 ms |
18680 KB |
ok, correct split |
7 |
Correct |
133 ms |
18804 KB |
ok, correct split |
8 |
Correct |
136 ms |
19576 KB |
ok, correct split |
9 |
Correct |
137 ms |
18680 KB |
ok, correct split |
10 |
Correct |
41 ms |
11128 KB |
ok, no valid answer |
11 |
Correct |
57 ms |
12664 KB |
ok, no valid answer |
12 |
Correct |
139 ms |
18332 KB |
ok, no valid answer |
13 |
Correct |
118 ms |
17208 KB |
ok, no valid answer |
14 |
Correct |
151 ms |
18792 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
ok, correct split |
2 |
Correct |
11 ms |
8184 KB |
ok, no valid answer |
3 |
Correct |
9 ms |
8184 KB |
ok, correct split |
4 |
Correct |
9 ms |
8184 KB |
ok, correct split |
5 |
Correct |
10 ms |
8184 KB |
ok, correct split |
6 |
Correct |
10 ms |
8184 KB |
ok, correct split |
7 |
Correct |
9 ms |
8184 KB |
ok, correct split |
8 |
Correct |
9 ms |
8184 KB |
ok, correct split |
9 |
Correct |
12 ms |
8492 KB |
ok, correct split |
10 |
Correct |
12 ms |
8440 KB |
ok, correct split |
11 |
Correct |
9 ms |
8184 KB |
ok, correct split |
12 |
Correct |
12 ms |
8440 KB |
ok, correct split |
13 |
Correct |
9 ms |
8184 KB |
ok, correct split |
14 |
Correct |
9 ms |
8184 KB |
ok, correct split |
15 |
Correct |
9 ms |
8184 KB |
ok, correct split |
16 |
Correct |
9 ms |
8184 KB |
ok, correct split |
17 |
Correct |
11 ms |
8184 KB |
ok, correct split |
18 |
Correct |
9 ms |
8184 KB |
ok, correct split |
19 |
Correct |
9 ms |
8184 KB |
ok, correct split |
20 |
Correct |
9 ms |
8312 KB |
ok, correct split |
21 |
Correct |
11 ms |
8440 KB |
ok, correct split |
22 |
Correct |
10 ms |
8444 KB |
ok, correct split |
23 |
Correct |
11 ms |
8440 KB |
ok, correct split |
24 |
Correct |
11 ms |
8440 KB |
ok, correct split |
25 |
Correct |
11 ms |
8440 KB |
ok, correct split |
26 |
Correct |
11 ms |
8568 KB |
ok, correct split |
27 |
Correct |
11 ms |
8568 KB |
ok, correct split |
28 |
Correct |
12 ms |
8568 KB |
ok, correct split |
29 |
Correct |
9 ms |
8184 KB |
ok, correct split |
30 |
Correct |
11 ms |
8568 KB |
ok, correct split |
31 |
Correct |
9 ms |
8184 KB |
ok, correct split |
32 |
Correct |
9 ms |
8184 KB |
ok, correct split |
33 |
Correct |
9 ms |
8184 KB |
ok, correct split |
34 |
Correct |
11 ms |
8440 KB |
ok, correct split |
35 |
Correct |
11 ms |
8440 KB |
ok, correct split |
36 |
Correct |
11 ms |
8440 KB |
ok, correct split |
37 |
Correct |
12 ms |
8440 KB |
ok, correct split |
38 |
Correct |
11 ms |
8440 KB |
ok, correct split |
39 |
Correct |
12 ms |
8568 KB |
ok, correct split |
40 |
Correct |
11 ms |
8440 KB |
ok, correct split |
41 |
Correct |
10 ms |
8312 KB |
ok, correct split |
42 |
Correct |
10 ms |
8312 KB |
ok, correct split |
43 |
Correct |
12 ms |
8568 KB |
ok, correct split |
44 |
Correct |
11 ms |
8440 KB |
ok, correct split |
45 |
Correct |
11 ms |
8440 KB |
ok, correct split |
46 |
Correct |
11 ms |
8440 KB |
ok, correct split |
47 |
Correct |
10 ms |
8440 KB |
ok, no valid answer |
48 |
Correct |
11 ms |
8440 KB |
ok, correct split |
49 |
Correct |
11 ms |
8440 KB |
ok, correct split |
50 |
Correct |
8 ms |
8184 KB |
ok, no valid answer |
51 |
Correct |
9 ms |
8184 KB |
ok, no valid answer |
52 |
Correct |
11 ms |
8440 KB |
ok, no valid answer |
53 |
Correct |
12 ms |
8440 KB |
ok, no valid answer |
54 |
Correct |
11 ms |
8440 KB |
ok, no valid answer |
55 |
Correct |
11 ms |
8440 KB |
ok, no valid answer |
56 |
Correct |
11 ms |
8440 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
ok, correct split |
2 |
Correct |
9 ms |
8184 KB |
ok, correct split |
3 |
Correct |
9 ms |
8184 KB |
ok, correct split |
4 |
Correct |
9 ms |
8184 KB |
ok, correct split |
5 |
Correct |
9 ms |
8220 KB |
ok, correct split |
6 |
Correct |
9 ms |
8184 KB |
ok, correct split |
7 |
Correct |
164 ms |
22876 KB |
ok, correct split |
8 |
Correct |
138 ms |
20984 KB |
ok, correct split |
9 |
Correct |
189 ms |
20344 KB |
ok, correct split |
10 |
Correct |
133 ms |
23032 KB |
ok, correct split |
11 |
Correct |
177 ms |
22992 KB |
ok, correct split |
12 |
Correct |
9 ms |
8184 KB |
ok, correct split |
13 |
Correct |
9 ms |
8184 KB |
ok, correct split |
14 |
Correct |
9 ms |
8188 KB |
ok, correct split |
15 |
Correct |
156 ms |
21028 KB |
ok, correct split |
16 |
Correct |
129 ms |
17016 KB |
ok, correct split |
17 |
Correct |
130 ms |
23032 KB |
ok, correct split |
18 |
Correct |
132 ms |
20804 KB |
ok, correct split |
19 |
Correct |
159 ms |
18936 KB |
ok, correct split |
20 |
Correct |
120 ms |
16888 KB |
ok, correct split |
21 |
Correct |
101 ms |
18772 KB |
ok, correct split |
22 |
Correct |
105 ms |
18900 KB |
ok, correct split |
23 |
Correct |
111 ms |
18816 KB |
ok, correct split |
24 |
Correct |
9 ms |
8184 KB |
ok, correct split |
25 |
Correct |
146 ms |
17016 KB |
ok, correct split |
26 |
Correct |
45 ms |
11768 KB |
ok, correct split |
27 |
Correct |
9 ms |
8312 KB |
ok, correct split |
28 |
Correct |
129 ms |
18952 KB |
ok, correct split |
29 |
Correct |
134 ms |
18680 KB |
ok, correct split |
30 |
Correct |
133 ms |
18804 KB |
ok, correct split |
31 |
Correct |
136 ms |
19576 KB |
ok, correct split |
32 |
Correct |
137 ms |
18680 KB |
ok, correct split |
33 |
Correct |
41 ms |
11128 KB |
ok, no valid answer |
34 |
Correct |
57 ms |
12664 KB |
ok, no valid answer |
35 |
Correct |
139 ms |
18332 KB |
ok, no valid answer |
36 |
Correct |
118 ms |
17208 KB |
ok, no valid answer |
37 |
Correct |
151 ms |
18792 KB |
ok, no valid answer |
38 |
Correct |
9 ms |
8184 KB |
ok, correct split |
39 |
Correct |
11 ms |
8184 KB |
ok, no valid answer |
40 |
Correct |
9 ms |
8184 KB |
ok, correct split |
41 |
Correct |
9 ms |
8184 KB |
ok, correct split |
42 |
Correct |
10 ms |
8184 KB |
ok, correct split |
43 |
Correct |
10 ms |
8184 KB |
ok, correct split |
44 |
Correct |
9 ms |
8184 KB |
ok, correct split |
45 |
Correct |
9 ms |
8184 KB |
ok, correct split |
46 |
Correct |
12 ms |
8492 KB |
ok, correct split |
47 |
Correct |
12 ms |
8440 KB |
ok, correct split |
48 |
Correct |
9 ms |
8184 KB |
ok, correct split |
49 |
Correct |
12 ms |
8440 KB |
ok, correct split |
50 |
Correct |
9 ms |
8184 KB |
ok, correct split |
51 |
Correct |
9 ms |
8184 KB |
ok, correct split |
52 |
Correct |
9 ms |
8184 KB |
ok, correct split |
53 |
Correct |
9 ms |
8184 KB |
ok, correct split |
54 |
Correct |
11 ms |
8184 KB |
ok, correct split |
55 |
Correct |
9 ms |
8184 KB |
ok, correct split |
56 |
Correct |
9 ms |
8184 KB |
ok, correct split |
57 |
Correct |
9 ms |
8312 KB |
ok, correct split |
58 |
Correct |
11 ms |
8440 KB |
ok, correct split |
59 |
Correct |
10 ms |
8444 KB |
ok, correct split |
60 |
Correct |
11 ms |
8440 KB |
ok, correct split |
61 |
Correct |
11 ms |
8440 KB |
ok, correct split |
62 |
Correct |
11 ms |
8440 KB |
ok, correct split |
63 |
Correct |
11 ms |
8568 KB |
ok, correct split |
64 |
Correct |
11 ms |
8568 KB |
ok, correct split |
65 |
Correct |
12 ms |
8568 KB |
ok, correct split |
66 |
Correct |
9 ms |
8184 KB |
ok, correct split |
67 |
Correct |
11 ms |
8568 KB |
ok, correct split |
68 |
Correct |
9 ms |
8184 KB |
ok, correct split |
69 |
Correct |
9 ms |
8184 KB |
ok, correct split |
70 |
Correct |
9 ms |
8184 KB |
ok, correct split |
71 |
Correct |
11 ms |
8440 KB |
ok, correct split |
72 |
Correct |
11 ms |
8440 KB |
ok, correct split |
73 |
Correct |
11 ms |
8440 KB |
ok, correct split |
74 |
Correct |
12 ms |
8440 KB |
ok, correct split |
75 |
Correct |
11 ms |
8440 KB |
ok, correct split |
76 |
Correct |
12 ms |
8568 KB |
ok, correct split |
77 |
Correct |
11 ms |
8440 KB |
ok, correct split |
78 |
Correct |
10 ms |
8312 KB |
ok, correct split |
79 |
Correct |
10 ms |
8312 KB |
ok, correct split |
80 |
Correct |
12 ms |
8568 KB |
ok, correct split |
81 |
Correct |
11 ms |
8440 KB |
ok, correct split |
82 |
Correct |
11 ms |
8440 KB |
ok, correct split |
83 |
Correct |
11 ms |
8440 KB |
ok, correct split |
84 |
Correct |
10 ms |
8440 KB |
ok, no valid answer |
85 |
Correct |
11 ms |
8440 KB |
ok, correct split |
86 |
Correct |
11 ms |
8440 KB |
ok, correct split |
87 |
Correct |
8 ms |
8184 KB |
ok, no valid answer |
88 |
Correct |
9 ms |
8184 KB |
ok, no valid answer |
89 |
Correct |
11 ms |
8440 KB |
ok, no valid answer |
90 |
Correct |
12 ms |
8440 KB |
ok, no valid answer |
91 |
Correct |
11 ms |
8440 KB |
ok, no valid answer |
92 |
Correct |
11 ms |
8440 KB |
ok, no valid answer |
93 |
Correct |
11 ms |
8440 KB |
ok, no valid answer |
94 |
Correct |
134 ms |
19268 KB |
ok, correct split |
95 |
Correct |
191 ms |
23324 KB |
ok, correct split |
96 |
Correct |
172 ms |
22132 KB |
ok, correct split |
97 |
Correct |
46 ms |
11768 KB |
ok, correct split |
98 |
Correct |
48 ms |
11768 KB |
ok, correct split |
99 |
Correct |
69 ms |
13260 KB |
ok, correct split |
100 |
Correct |
166 ms |
19320 KB |
ok, correct split |
101 |
Correct |
158 ms |
18680 KB |
ok, correct split |
102 |
Correct |
146 ms |
18928 KB |
ok, correct split |
103 |
Correct |
134 ms |
19164 KB |
ok, correct split |
104 |
Correct |
135 ms |
19684 KB |
ok, correct split |
105 |
Correct |
71 ms |
13944 KB |
ok, correct split |
106 |
Correct |
165 ms |
24676 KB |
ok, correct split |
107 |
Correct |
123 ms |
17144 KB |
ok, correct split |
108 |
Correct |
116 ms |
17144 KB |
ok, correct split |
109 |
Correct |
176 ms |
18908 KB |
ok, correct split |
110 |
Correct |
165 ms |
19828 KB |
ok, correct split |
111 |
Correct |
175 ms |
19952 KB |
ok, correct split |
112 |
Correct |
173 ms |
20176 KB |
ok, correct split |
113 |
Correct |
161 ms |
20080 KB |
ok, correct split |
114 |
Correct |
23 ms |
9592 KB |
ok, correct split |
115 |
Correct |
22 ms |
9464 KB |
ok, correct split |
116 |
Correct |
180 ms |
19824 KB |
ok, correct split |
117 |
Correct |
160 ms |
19696 KB |
ok, correct split |
118 |
Correct |
125 ms |
16892 KB |
ok, correct split |
119 |
Correct |
119 ms |
16888 KB |
ok, correct split |
120 |
Correct |
131 ms |
20088 KB |
ok, correct split |
121 |
Correct |
112 ms |
17016 KB |
ok, no valid answer |
122 |
Correct |
115 ms |
17652 KB |
ok, no valid answer |
123 |
Correct |
166 ms |
19452 KB |
ok, no valid answer |
124 |
Correct |
159 ms |
19324 KB |
ok, no valid answer |
125 |
Correct |
137 ms |
19056 KB |
ok, no valid answer |
126 |
Correct |
107 ms |
17776 KB |
ok, no valid answer |
127 |
Correct |
153 ms |
19056 KB |
ok, no valid answer |