#include "split.h"
#include <bits/stdc++.h>
using namespace std;
#define ar array
const int mxN=1e5;
ar<int, 2> ps[3];
vector<int> ans, adj1[mxN], adj2[2*mxN], st, adj3[mxN], adj4[mxN];
int n, tin[mxN], low[mxN], dt=1, bccI, s[2*mxN], nxt[mxN][2], si[mxN], pa[mxN];
bool cb[mxN], bl[mxN];
void dfs1(int u=0, int p=-1) {
tin[u]=low[u]=dt++;
st.push_back(u);
for(int v : adj1[u]) {
if(!tin[v]) {
int sts=st.size();
dfs1(v, u);
low[u]=min(low[v], low[u]);
if(low[v]>=tin[u]) {
while(st.size()>sts) {
adj2[n+bccI].push_back(st.back());
st.pop_back();
}
adj2[n+bccI].push_back(u);
adj2[u].push_back(n+bccI++);
}
} else if(v^p)
low[u]=min(tin[v], low[u]);
}
}
void dfs2(int u=0, int p=-1) {
s[u]=u<n;
for(int v : adj2[u]) {
if(v==p)
continue;
dfs2(v, u);
s[u]+=s[v];
}
}
void dfs4(int u, int p=-1) {
tin[u]=dt++;
pa[u]=p;
for(int v : adj3[u]) {
if(!tin[v])
dfs4(v, u);
else if(tin[v]>tin[u])
adj4[u].push_back(v);
}
}
void dfs5(int u) {
tin[u]=0;
for(int v : adj4[u]) {
for(int c=u, d=si[u]>0; !si[v]; v=pa[v], c=nxt[c][d]) {
si[v]=-si[u];
nxt[v][d^1]=c;
nxt[v][d]=nxt[c][d];
nxt[c][d]=v;
if(~nxt[v][d])
nxt[nxt[v][d]][d^1]=v;
}
}
for(int v : adj3[u])
if(tin[v])
dfs5(v);
}
void dfs6(int u, int c, int &l) {
if(!l)
return;
ans[u]=c;
--l;
for(int v : adj1[u])
if(!bl[v]&&ans[v]==ps[2][1])
dfs6(v, c, l);
}
void as(vector<int> a, vector<int> b) {
if(ans[0])
return;
fill(ans.begin(), ans.end(), ps[2][1]);
int la=ps[0][0], lb=ps[1][0];
for(int c : b)
bl[c]=1;
dfs6(a[0], ps[0][1], la);
for(int c : b)
bl[c]=0;
dfs6(b[0], ps[1][1], lb);
}
void dfs3(int u=0, int p=-1) {
if(u>=n) {
ar<int, 2> mx{};
for(int v : adj2[u]) {
cb[v]=1;
mx=max(ar<int, 2>{s[v], v}, mx);
}
if(mx[0]>=ps[1][0]) {
if(n-mx[0]>=ps[0][0]) {
vector<int> a=adj2[u];
a.erase(find(a.begin(), a.end(), mx[1]));
as(a, {mx[1]});
}
} else if(mx[0]>=ps[0][0]) {
if(n-mx[0]>=ps[1][0]) {
vector<int> b=adj2[u];
b.erase(find(b.begin(), b.end(), mx[1]));
as({mx[1]}, b);
}
} else {
for(int v : adj2[u])
for(int w : adj1[v])
if(cb[w])
adj3[v].push_back(w);
int cs=0, cu=adj2[u][0];
dfs4(cu);
nxt[cu][0]=nxt[cu][1]=-1;
si[cu]=1;
dfs5(cu);
vector<int> a, b;
while(cs<ps[0][0]) {
cs+=s[cu];
a.push_back(cu);
cu=nxt[cu][1];
}
while(~cu) {
b.push_back(cu);
cu=nxt[cu][1];
}
as(a, b);
}
for(int v : adj2[u]) {
cb[v]=0;
adj3[v].clear();
adj4[v].clear();
si[v]=0;
}
}
for(int v : adj2[u]) {
if(v==p)
continue;
s[u]=n-s[v];
dfs3(v, u);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
::n=n;
ps[0]={a, 1};
ps[1]={b, 2};
ps[2]={c, 3};
sort(ps, ps+3);
for(int i=0; i<p.size(); ++i) {
adj1[p[i]].push_back(q[i]);
adj1[q[i]].push_back(p[i]);
}
ans=vector<int>(n);
dfs1();
dfs2();
memset(tin, 0, 4*n);
dfs3();
return ans;
}
Compilation message
split.cpp: In function 'void dfs1(int, int)':
split.cpp:22:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
22 | while(st.size()>sts) {
| ~~~~~~~~~^~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:157:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
157 | for(int i=0; i<p.size(); ++i) {
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
ok, correct split |
2 |
Correct |
8 ms |
12032 KB |
ok, correct split |
3 |
Correct |
8 ms |
12032 KB |
ok, correct split |
4 |
Correct |
7 ms |
12032 KB |
ok, correct split |
5 |
Correct |
7 ms |
12032 KB |
ok, correct split |
6 |
Correct |
7 ms |
12160 KB |
ok, correct split |
7 |
Correct |
271 ms |
74996 KB |
ok, correct split |
8 |
Correct |
222 ms |
60532 KB |
ok, correct split |
9 |
Correct |
243 ms |
55928 KB |
ok, correct split |
10 |
Correct |
131 ms |
30704 KB |
ok, correct split |
11 |
Correct |
220 ms |
35436 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
ok, correct split |
2 |
Correct |
9 ms |
12032 KB |
ok, correct split |
3 |
Correct |
7 ms |
12032 KB |
ok, correct split |
4 |
Correct |
171 ms |
28368 KB |
ok, correct split |
5 |
Correct |
172 ms |
25592 KB |
ok, correct split |
6 |
Correct |
116 ms |
30708 KB |
ok, correct split |
7 |
Correct |
239 ms |
59140 KB |
ok, correct split |
8 |
Correct |
184 ms |
24572 KB |
ok, correct split |
9 |
Correct |
133 ms |
20856 KB |
ok, correct split |
10 |
Correct |
140 ms |
24304 KB |
ok, correct split |
11 |
Correct |
115 ms |
24304 KB |
ok, correct split |
12 |
Correct |
115 ms |
24688 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
12032 KB |
ok, correct split |
2 |
Correct |
162 ms |
24444 KB |
ok, correct split |
3 |
Correct |
64 ms |
17528 KB |
ok, correct split |
4 |
Correct |
8 ms |
12032 KB |
ok, correct split |
5 |
Correct |
192 ms |
43896 KB |
ok, correct split |
6 |
Correct |
194 ms |
42232 KB |
ok, correct split |
7 |
Correct |
183 ms |
41080 KB |
ok, correct split |
8 |
Correct |
177 ms |
49732 KB |
ok, correct split |
9 |
Correct |
179 ms |
40056 KB |
ok, correct split |
10 |
Correct |
43 ms |
16636 KB |
ok, no valid answer |
11 |
Correct |
63 ms |
18840 KB |
ok, no valid answer |
12 |
Correct |
118 ms |
25204 KB |
ok, no valid answer |
13 |
Correct |
143 ms |
25592 KB |
ok, no valid answer |
14 |
Correct |
96 ms |
24688 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12032 KB |
ok, correct split |
2 |
Correct |
8 ms |
12032 KB |
ok, no valid answer |
3 |
Correct |
8 ms |
12032 KB |
ok, correct split |
4 |
Correct |
8 ms |
12032 KB |
ok, correct split |
5 |
Correct |
8 ms |
12032 KB |
ok, correct split |
6 |
Correct |
7 ms |
12032 KB |
ok, correct split |
7 |
Correct |
8 ms |
12032 KB |
ok, correct split |
8 |
Correct |
8 ms |
12032 KB |
ok, correct split |
9 |
Correct |
10 ms |
12544 KB |
ok, correct split |
10 |
Correct |
11 ms |
12416 KB |
ok, correct split |
11 |
Correct |
8 ms |
12192 KB |
ok, correct split |
12 |
Incorrect |
13 ms |
12544 KB |
invalid split: #1=1, #2=1600, #3=800 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
ok, correct split |
2 |
Correct |
8 ms |
12032 KB |
ok, correct split |
3 |
Correct |
8 ms |
12032 KB |
ok, correct split |
4 |
Correct |
7 ms |
12032 KB |
ok, correct split |
5 |
Correct |
7 ms |
12032 KB |
ok, correct split |
6 |
Correct |
7 ms |
12160 KB |
ok, correct split |
7 |
Correct |
271 ms |
74996 KB |
ok, correct split |
8 |
Correct |
222 ms |
60532 KB |
ok, correct split |
9 |
Correct |
243 ms |
55928 KB |
ok, correct split |
10 |
Correct |
131 ms |
30704 KB |
ok, correct split |
11 |
Correct |
220 ms |
35436 KB |
ok, correct split |
12 |
Correct |
8 ms |
12032 KB |
ok, correct split |
13 |
Correct |
9 ms |
12032 KB |
ok, correct split |
14 |
Correct |
7 ms |
12032 KB |
ok, correct split |
15 |
Correct |
171 ms |
28368 KB |
ok, correct split |
16 |
Correct |
172 ms |
25592 KB |
ok, correct split |
17 |
Correct |
116 ms |
30708 KB |
ok, correct split |
18 |
Correct |
239 ms |
59140 KB |
ok, correct split |
19 |
Correct |
184 ms |
24572 KB |
ok, correct split |
20 |
Correct |
133 ms |
20856 KB |
ok, correct split |
21 |
Correct |
140 ms |
24304 KB |
ok, correct split |
22 |
Correct |
115 ms |
24304 KB |
ok, correct split |
23 |
Correct |
115 ms |
24688 KB |
ok, correct split |
24 |
Correct |
9 ms |
12032 KB |
ok, correct split |
25 |
Correct |
162 ms |
24444 KB |
ok, correct split |
26 |
Correct |
64 ms |
17528 KB |
ok, correct split |
27 |
Correct |
8 ms |
12032 KB |
ok, correct split |
28 |
Correct |
192 ms |
43896 KB |
ok, correct split |
29 |
Correct |
194 ms |
42232 KB |
ok, correct split |
30 |
Correct |
183 ms |
41080 KB |
ok, correct split |
31 |
Correct |
177 ms |
49732 KB |
ok, correct split |
32 |
Correct |
179 ms |
40056 KB |
ok, correct split |
33 |
Correct |
43 ms |
16636 KB |
ok, no valid answer |
34 |
Correct |
63 ms |
18840 KB |
ok, no valid answer |
35 |
Correct |
118 ms |
25204 KB |
ok, no valid answer |
36 |
Correct |
143 ms |
25592 KB |
ok, no valid answer |
37 |
Correct |
96 ms |
24688 KB |
ok, no valid answer |
38 |
Correct |
7 ms |
12032 KB |
ok, correct split |
39 |
Correct |
8 ms |
12032 KB |
ok, no valid answer |
40 |
Correct |
8 ms |
12032 KB |
ok, correct split |
41 |
Correct |
8 ms |
12032 KB |
ok, correct split |
42 |
Correct |
8 ms |
12032 KB |
ok, correct split |
43 |
Correct |
7 ms |
12032 KB |
ok, correct split |
44 |
Correct |
8 ms |
12032 KB |
ok, correct split |
45 |
Correct |
8 ms |
12032 KB |
ok, correct split |
46 |
Correct |
10 ms |
12544 KB |
ok, correct split |
47 |
Correct |
11 ms |
12416 KB |
ok, correct split |
48 |
Correct |
8 ms |
12192 KB |
ok, correct split |
49 |
Incorrect |
13 ms |
12544 KB |
invalid split: #1=1, #2=1600, #3=800 |
50 |
Halted |
0 ms |
0 KB |
- |