#include "split.h"
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
const int N = 100005;
int n;
vector<pair<int, int> > sad;
vector<int> res;
int dsu[N];
int find(int v){
return v == dsu[v]? v : dsu[v] = find(dsu[v]);
}
vector<pair<int, int> > supp;
vector<int> adj1[N];
int sz[N];
int cen(int v, int p){
sz[v] = 1;
int w = -1;
for(auto& x : adj1[v]){
if(x == p) continue;
w = max(w, cen(x, v));
sz[v] += sz[x];
}
if(w != -1) return w;
if(n - sz[v] <= n / 2) return v;
return -1;
}
void mina(int v, int p, int c){
if(sad[c].ff == 0) return;
--sad[c].ff;
res[v] = sad[c].ss;
for(auto& x : adj1[v]){
if(x == p) continue;
mina(x, v, c);
}
}
int col[N];
void pnt(int v, int p, int c){
col[v] = c;
++sz[c];
for(auto& x : adj1[v]){
if(x == p)
continue;
pnt(x, v, c);
}
}
vector<int> adj2[N];
bool vis[N];
int ss;
bool dfs(int v, int r){
vis[v] = 1;
ss += sz[v];
dsu[v] = r;
if(ss >= sad[0].ff) return 1;
for(auto& x : adj2[v])
if(dsu[x] != r)
if(dfs(x, r)) return 1;
return 0;
}
void minari(int v, int c){
if(sad[c].ff == 0) return;
res[v] = sad[c].ss;
--sad[c].ff;
for(auto& x : adj1[v])
if(col[x] == col[v] && !res[x])
minari(x, c);
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
::n = n;
res.resize(n);
for(int i = 0; i < n; ++i)
dsu[i] = i;
sad.push_back({a, 1});
sad.push_back({b, 2});
sad.push_back({c, 3});
sort(sad.begin(), sad.end());
for(int i = 0; i < p.size(); ++i){
if(find(p[i]) == find(q[i])) supp.push_back({p[i], q[i]});
else {
dsu[find(p[i])] = find(q[i]);
adj1[p[i]].push_back(q[i]);
adj1[q[i]].push_back(p[i]);
}
}
int r = cen(0, -1);
cen(r, -1);
for(int i = 0; i < adj1[r].size(); ++i){
if(sz[adj1[r][i]] >= sad[0].ff){
mina(adj1[r][i], r, 0);
mina(r, adj1[r][i], 1);
for(int j = 0; j < n; ++j)
if(!res[j])
res[j] = sad[2].ss;
return res;
}
}
for(int i = 0; i < n; ++i)
sz[i] = 0;
for(int i = 0; i < adj1[r].size(); ++i)
pnt(adj1[r][i], r, i + 1);
for(auto& x : supp){
if(col[x.ff] == col[x.ss] || x.ff == r || x.ss == r) continue;
adj2[col[x.ff]].push_back(col[x.ss]);
adj2[col[x.ss]].push_back(col[x.ff]);
}
for(int i = 0; i < n; ++i)
dsu[i] = i;
for(int i = 0; i <= n; ++i){
ss = 0;
if(!vis[i] && dfs(i, i)){
for(int j = 0; j < n; ++j){
col[j] = dsu[col[j]];
if(col[j] != i) col[j] = 0;
}
for(auto& x : supp){
adj1[x.ff].push_back(x.ss);
adj1[x.ss].push_back(x.ff);
}
minari(adj1[r][i - 1], 0);
minari(r, 1);
for(int j = 0; j < n; ++j)
if(!res[j])
res[j] = sad[2].ss;
return res;
}
}
return res;
}
Compilation message
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:95:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < p.size(); ++i){
~~^~~~~~~~~~
split.cpp:107:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < adj1[r].size(); ++i){
~~^~~~~~~~~~~~~~~~
split.cpp:122:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < adj1[r].size(); ++i)
~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4992 KB |
ok, correct split |
2 |
Correct |
8 ms |
4992 KB |
ok, correct split |
3 |
Correct |
9 ms |
4992 KB |
ok, correct split |
4 |
Correct |
7 ms |
4992 KB |
ok, correct split |
5 |
Correct |
7 ms |
4992 KB |
ok, correct split |
6 |
Correct |
9 ms |
4992 KB |
ok, correct split |
7 |
Correct |
134 ms |
17272 KB |
ok, correct split |
8 |
Correct |
100 ms |
15480 KB |
ok, correct split |
9 |
Correct |
106 ms |
14852 KB |
ok, correct split |
10 |
Correct |
111 ms |
17376 KB |
ok, correct split |
11 |
Correct |
116 ms |
16248 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4968 KB |
ok, correct split |
2 |
Correct |
8 ms |
4992 KB |
ok, correct split |
3 |
Correct |
7 ms |
4992 KB |
ok, correct split |
4 |
Correct |
115 ms |
12504 KB |
ok, correct split |
5 |
Correct |
94 ms |
11384 KB |
ok, correct split |
6 |
Correct |
120 ms |
17272 KB |
ok, correct split |
7 |
Correct |
107 ms |
15224 KB |
ok, correct split |
8 |
Correct |
135 ms |
13484 KB |
ok, correct split |
9 |
Correct |
143 ms |
11384 KB |
ok, correct split |
10 |
Correct |
65 ms |
11736 KB |
ok, correct split |
11 |
Correct |
99 ms |
11632 KB |
ok, correct split |
12 |
Correct |
63 ms |
11632 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4992 KB |
ok, correct split |
2 |
Correct |
102 ms |
11360 KB |
ok, correct split |
3 |
Correct |
36 ms |
7552 KB |
ok, correct split |
4 |
Correct |
7 ms |
4992 KB |
ok, correct split |
5 |
Correct |
102 ms |
13304 KB |
ok, correct split |
6 |
Correct |
103 ms |
13176 KB |
ok, correct split |
7 |
Correct |
105 ms |
13176 KB |
ok, correct split |
8 |
Correct |
107 ms |
14072 KB |
ok, correct split |
9 |
Correct |
105 ms |
13176 KB |
ok, correct split |
10 |
Correct |
33 ms |
7416 KB |
ok, no valid answer |
11 |
Correct |
46 ms |
8440 KB |
ok, no valid answer |
12 |
Correct |
77 ms |
12148 KB |
ok, no valid answer |
13 |
Correct |
104 ms |
11896 KB |
ok, no valid answer |
14 |
Correct |
64 ms |
12144 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
ok, correct split |
2 |
Correct |
7 ms |
4992 KB |
ok, no valid answer |
3 |
Correct |
7 ms |
5120 KB |
ok, correct split |
4 |
Correct |
7 ms |
4992 KB |
ok, correct split |
5 |
Correct |
7 ms |
4992 KB |
ok, correct split |
6 |
Correct |
7 ms |
4992 KB |
ok, correct split |
7 |
Correct |
7 ms |
4992 KB |
ok, correct split |
8 |
Correct |
7 ms |
4992 KB |
ok, correct split |
9 |
Correct |
10 ms |
5248 KB |
ok, correct split |
10 |
Correct |
9 ms |
5248 KB |
ok, correct split |
11 |
Correct |
7 ms |
5120 KB |
ok, correct split |
12 |
Correct |
10 ms |
5376 KB |
ok, correct split |
13 |
Correct |
7 ms |
4992 KB |
ok, correct split |
14 |
Correct |
7 ms |
5120 KB |
ok, correct split |
15 |
Correct |
7 ms |
5120 KB |
ok, correct split |
16 |
Correct |
8 ms |
4992 KB |
ok, correct split |
17 |
Correct |
7 ms |
4992 KB |
ok, correct split |
18 |
Correct |
7 ms |
5120 KB |
ok, correct split |
19 |
Correct |
8 ms |
5120 KB |
ok, correct split |
20 |
Correct |
8 ms |
5120 KB |
ok, correct split |
21 |
Correct |
9 ms |
5248 KB |
ok, correct split |
22 |
Correct |
9 ms |
5248 KB |
ok, correct split |
23 |
Correct |
10 ms |
5376 KB |
ok, correct split |
24 |
Correct |
9 ms |
5248 KB |
ok, correct split |
25 |
Correct |
12 ms |
5248 KB |
ok, correct split |
26 |
Correct |
9 ms |
5376 KB |
ok, correct split |
27 |
Correct |
12 ms |
5376 KB |
ok, correct split |
28 |
Correct |
9 ms |
5248 KB |
ok, correct split |
29 |
Correct |
8 ms |
5120 KB |
ok, correct split |
30 |
Correct |
10 ms |
5376 KB |
ok, correct split |
31 |
Correct |
8 ms |
5120 KB |
ok, correct split |
32 |
Correct |
8 ms |
4992 KB |
ok, correct split |
33 |
Correct |
7 ms |
4992 KB |
ok, correct split |
34 |
Correct |
9 ms |
5248 KB |
ok, correct split |
35 |
Correct |
9 ms |
5248 KB |
ok, correct split |
36 |
Correct |
9 ms |
5248 KB |
ok, correct split |
37 |
Correct |
10 ms |
5376 KB |
ok, correct split |
38 |
Correct |
10 ms |
5376 KB |
ok, correct split |
39 |
Correct |
10 ms |
5376 KB |
ok, correct split |
40 |
Correct |
10 ms |
5376 KB |
ok, correct split |
41 |
Correct |
9 ms |
5248 KB |
ok, correct split |
42 |
Correct |
9 ms |
5120 KB |
ok, correct split |
43 |
Correct |
10 ms |
5504 KB |
ok, correct split |
44 |
Correct |
10 ms |
5376 KB |
ok, correct split |
45 |
Correct |
10 ms |
5376 KB |
ok, correct split |
46 |
Correct |
10 ms |
5248 KB |
ok, correct split |
47 |
Correct |
10 ms |
5380 KB |
ok, no valid answer |
48 |
Correct |
9 ms |
5248 KB |
ok, correct split |
49 |
Correct |
9 ms |
5248 KB |
ok, correct split |
50 |
Correct |
7 ms |
4992 KB |
ok, no valid answer |
51 |
Correct |
7 ms |
4992 KB |
ok, no valid answer |
52 |
Correct |
9 ms |
5248 KB |
ok, no valid answer |
53 |
Correct |
10 ms |
5376 KB |
ok, no valid answer |
54 |
Correct |
9 ms |
5248 KB |
ok, no valid answer |
55 |
Correct |
10 ms |
5352 KB |
ok, no valid answer |
56 |
Correct |
9 ms |
5300 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4992 KB |
ok, correct split |
2 |
Correct |
8 ms |
4992 KB |
ok, correct split |
3 |
Correct |
9 ms |
4992 KB |
ok, correct split |
4 |
Correct |
7 ms |
4992 KB |
ok, correct split |
5 |
Correct |
7 ms |
4992 KB |
ok, correct split |
6 |
Correct |
9 ms |
4992 KB |
ok, correct split |
7 |
Correct |
134 ms |
17272 KB |
ok, correct split |
8 |
Correct |
100 ms |
15480 KB |
ok, correct split |
9 |
Correct |
106 ms |
14852 KB |
ok, correct split |
10 |
Correct |
111 ms |
17376 KB |
ok, correct split |
11 |
Correct |
116 ms |
16248 KB |
ok, correct split |
12 |
Correct |
8 ms |
4968 KB |
ok, correct split |
13 |
Correct |
8 ms |
4992 KB |
ok, correct split |
14 |
Correct |
7 ms |
4992 KB |
ok, correct split |
15 |
Correct |
115 ms |
12504 KB |
ok, correct split |
16 |
Correct |
94 ms |
11384 KB |
ok, correct split |
17 |
Correct |
120 ms |
17272 KB |
ok, correct split |
18 |
Correct |
107 ms |
15224 KB |
ok, correct split |
19 |
Correct |
135 ms |
13484 KB |
ok, correct split |
20 |
Correct |
143 ms |
11384 KB |
ok, correct split |
21 |
Correct |
65 ms |
11736 KB |
ok, correct split |
22 |
Correct |
99 ms |
11632 KB |
ok, correct split |
23 |
Correct |
63 ms |
11632 KB |
ok, correct split |
24 |
Correct |
9 ms |
4992 KB |
ok, correct split |
25 |
Correct |
102 ms |
11360 KB |
ok, correct split |
26 |
Correct |
36 ms |
7552 KB |
ok, correct split |
27 |
Correct |
7 ms |
4992 KB |
ok, correct split |
28 |
Correct |
102 ms |
13304 KB |
ok, correct split |
29 |
Correct |
103 ms |
13176 KB |
ok, correct split |
30 |
Correct |
105 ms |
13176 KB |
ok, correct split |
31 |
Correct |
107 ms |
14072 KB |
ok, correct split |
32 |
Correct |
105 ms |
13176 KB |
ok, correct split |
33 |
Correct |
33 ms |
7416 KB |
ok, no valid answer |
34 |
Correct |
46 ms |
8440 KB |
ok, no valid answer |
35 |
Correct |
77 ms |
12148 KB |
ok, no valid answer |
36 |
Correct |
104 ms |
11896 KB |
ok, no valid answer |
37 |
Correct |
64 ms |
12144 KB |
ok, no valid answer |
38 |
Correct |
7 ms |
4992 KB |
ok, correct split |
39 |
Correct |
7 ms |
4992 KB |
ok, no valid answer |
40 |
Correct |
7 ms |
5120 KB |
ok, correct split |
41 |
Correct |
7 ms |
4992 KB |
ok, correct split |
42 |
Correct |
7 ms |
4992 KB |
ok, correct split |
43 |
Correct |
7 ms |
4992 KB |
ok, correct split |
44 |
Correct |
7 ms |
4992 KB |
ok, correct split |
45 |
Correct |
7 ms |
4992 KB |
ok, correct split |
46 |
Correct |
10 ms |
5248 KB |
ok, correct split |
47 |
Correct |
9 ms |
5248 KB |
ok, correct split |
48 |
Correct |
7 ms |
5120 KB |
ok, correct split |
49 |
Correct |
10 ms |
5376 KB |
ok, correct split |
50 |
Correct |
7 ms |
4992 KB |
ok, correct split |
51 |
Correct |
7 ms |
5120 KB |
ok, correct split |
52 |
Correct |
7 ms |
5120 KB |
ok, correct split |
53 |
Correct |
8 ms |
4992 KB |
ok, correct split |
54 |
Correct |
7 ms |
4992 KB |
ok, correct split |
55 |
Correct |
7 ms |
5120 KB |
ok, correct split |
56 |
Correct |
8 ms |
5120 KB |
ok, correct split |
57 |
Correct |
8 ms |
5120 KB |
ok, correct split |
58 |
Correct |
9 ms |
5248 KB |
ok, correct split |
59 |
Correct |
9 ms |
5248 KB |
ok, correct split |
60 |
Correct |
10 ms |
5376 KB |
ok, correct split |
61 |
Correct |
9 ms |
5248 KB |
ok, correct split |
62 |
Correct |
12 ms |
5248 KB |
ok, correct split |
63 |
Correct |
9 ms |
5376 KB |
ok, correct split |
64 |
Correct |
12 ms |
5376 KB |
ok, correct split |
65 |
Correct |
9 ms |
5248 KB |
ok, correct split |
66 |
Correct |
8 ms |
5120 KB |
ok, correct split |
67 |
Correct |
10 ms |
5376 KB |
ok, correct split |
68 |
Correct |
8 ms |
5120 KB |
ok, correct split |
69 |
Correct |
8 ms |
4992 KB |
ok, correct split |
70 |
Correct |
7 ms |
4992 KB |
ok, correct split |
71 |
Correct |
9 ms |
5248 KB |
ok, correct split |
72 |
Correct |
9 ms |
5248 KB |
ok, correct split |
73 |
Correct |
9 ms |
5248 KB |
ok, correct split |
74 |
Correct |
10 ms |
5376 KB |
ok, correct split |
75 |
Correct |
10 ms |
5376 KB |
ok, correct split |
76 |
Correct |
10 ms |
5376 KB |
ok, correct split |
77 |
Correct |
10 ms |
5376 KB |
ok, correct split |
78 |
Correct |
9 ms |
5248 KB |
ok, correct split |
79 |
Correct |
9 ms |
5120 KB |
ok, correct split |
80 |
Correct |
10 ms |
5504 KB |
ok, correct split |
81 |
Correct |
10 ms |
5376 KB |
ok, correct split |
82 |
Correct |
10 ms |
5376 KB |
ok, correct split |
83 |
Correct |
10 ms |
5248 KB |
ok, correct split |
84 |
Correct |
10 ms |
5380 KB |
ok, no valid answer |
85 |
Correct |
9 ms |
5248 KB |
ok, correct split |
86 |
Correct |
9 ms |
5248 KB |
ok, correct split |
87 |
Correct |
7 ms |
4992 KB |
ok, no valid answer |
88 |
Correct |
7 ms |
4992 KB |
ok, no valid answer |
89 |
Correct |
9 ms |
5248 KB |
ok, no valid answer |
90 |
Correct |
10 ms |
5376 KB |
ok, no valid answer |
91 |
Correct |
9 ms |
5248 KB |
ok, no valid answer |
92 |
Correct |
10 ms |
5352 KB |
ok, no valid answer |
93 |
Correct |
9 ms |
5300 KB |
ok, no valid answer |
94 |
Correct |
106 ms |
13184 KB |
ok, correct split |
95 |
Correct |
136 ms |
15980 KB |
ok, correct split |
96 |
Correct |
146 ms |
17900 KB |
ok, correct split |
97 |
Correct |
35 ms |
8056 KB |
ok, correct split |
98 |
Correct |
38 ms |
8184 KB |
ok, correct split |
99 |
Correct |
53 ms |
9968 KB |
ok, correct split |
100 |
Correct |
129 ms |
16108 KB |
ok, correct split |
101 |
Correct |
117 ms |
14956 KB |
ok, correct split |
102 |
Correct |
153 ms |
17128 KB |
ok, correct split |
103 |
Correct |
127 ms |
16620 KB |
ok, correct split |
104 |
Correct |
109 ms |
16496 KB |
ok, correct split |
105 |
Correct |
55 ms |
9724 KB |
ok, correct split |
106 |
Correct |
102 ms |
16280 KB |
ok, correct split |
107 |
Correct |
119 ms |
12536 KB |
ok, correct split |
108 |
Correct |
103 ms |
12536 KB |
ok, correct split |
109 |
Correct |
154 ms |
15676 KB |
ok, correct split |
110 |
Correct |
179 ms |
18284 KB |
ok, correct split |
111 |
Correct |
177 ms |
18316 KB |
ok, correct split |
112 |
Correct |
179 ms |
18896 KB |
ok, correct split |
113 |
Correct |
162 ms |
18952 KB |
ok, correct split |
114 |
Correct |
21 ms |
6656 KB |
ok, correct split |
115 |
Correct |
20 ms |
6528 KB |
ok, correct split |
116 |
Correct |
125 ms |
16108 KB |
ok, correct split |
117 |
Correct |
120 ms |
15980 KB |
ok, correct split |
118 |
Correct |
98 ms |
12536 KB |
ok, correct split |
119 |
Correct |
105 ms |
12920 KB |
ok, correct split |
120 |
Correct |
160 ms |
15224 KB |
ok, correct split |
121 |
Correct |
92 ms |
13048 KB |
ok, no valid answer |
122 |
Correct |
97 ms |
13112 KB |
ok, no valid answer |
123 |
Correct |
137 ms |
16492 KB |
ok, no valid answer |
124 |
Correct |
148 ms |
16492 KB |
ok, no valid answer |
125 |
Correct |
90 ms |
14960 KB |
ok, no valid answer |
126 |
Correct |
58 ms |
12704 KB |
ok, no valid answer |
127 |
Correct |
101 ms |
15980 KB |
ok, no valid answer |