#include <bits/stdc++.h>
using namespace std;
#include "sphinx.h"
//#include "grader.cpp"
#define sz(x) int(x.size())
int n, mmo;
int p[255], sz[255], p2[255], sz2[255], idxo = 1;
vector<int> adj57[255], tr[255], bck[255];
int vis[255];
int findp2(int u) {
return p2[u] = (p2[u] == u ? u : findp2(p2[u]));
}
bool merge2(int u, int v) {
u = findp2(u), v = findp2(v);
if (u == v)return false;
if (sz2[u] < sz2[v])swap(u, v);
sz2[u] += sz2[v];
p2[v] = u;
return true;
}
int findp(int u) {
return p[u] = (p[u] == u ? u : findp(p[u]));
}
void merge(int u, int v) {
u = findp(u), v = findp(v);
if (u == v)return;
if (sz[u] < sz[v])swap(u, v);
sz[u] += sz[v];
p[v] = u;
}
bool chk(vector<int> v) {
for (int i = 0; i < n; i++) {
p2[i] = i;
sz2[i] = 1;
}
int comps = n;
for (int i = 0; i < n; i++) {
for (auto &vv : adj57[i]) {
if (~v[i] && v[i] == v[vv]) {
comps -= merge2(i, vv);
} else if (v[i] == -1 && v[vv] == -1 && findp(i) == findp(vv)) {
comps -= merge2(i, vv);
}
}
}
int x = perform_experiment(v);
return (comps > x);
}
bool chk2(int u, int v) {
for (int i = 0; i < n; i++) {
p2[i] = i;
sz2[i] = 1;
}
int comps = n;
vector<int> e(n, n);
e[u] = e[v] = -1;
for (int i = 0; i < n; i++) {
for (auto &vv : adj57[i]) {
if (e[i] == e[vv]) {
comps -= merge2(i, vv);
}
}
}
int x = perform_experiment(e);
return (comps == x);
}
void init(int u, int pr) {
vis[u] = idxo++;
for (auto &v : adj57[u]) {
if (v == pr)continue;
if (vis[v]) {
if (vis[v] < vis[u])bck[u].push_back(v);
continue;
}
init(v, u);
tr[u].push_back(v);
}
}
void soly(int u, vector<int> vvo) {
if (vvo.empty())return;
int l = 0, r = int(vvo.size()) - 1, id = -1;
while (l <= r) {
int m = (l + r) >> 1;
vector<int> e(n, n);
for (int j = 0; j <= m; j++) {
for (int i = 0; i < n; i++) {
if (findp(i) == vvo[j])e[i] = -1;
}
}
e[u] = -1;
if (chk(e)) {
id = m;
r = m-1;
} else {
l = m+1;
}
}
if (~id) {
merge(u, vvo[id]);
} else {
return;
}
vector<int> xx;
for (int i = id+1; i < sz(vvo); i++) {
xx.push_back(vvo[i]);
}
soly(u, xx);
}
void dfs(int u) {
vector<int> vvo;
for (auto &v : bck[u]) {
if (findp(v) != findp(u))vvo.push_back(findp(v));
}
sort(vvo.begin(), vvo.end());
vvo.erase(unique(vvo.begin(), vvo.end()), vvo.end());
soly(u, vvo);
for (auto &v : tr[u]) {
if (chk2(u, v)) {
merge(u, v);
}
dfs(v);
}
}
std::vector<int> find_colours(int NH, std::vector<int> X, std::vector<int> Y) {
n = NH;
vector<int> ret(n, 0);
for (int i = 0; i < n; i++) {
p[i] = i;
sz[i] = 1;
adj57[i].clear();
tr[i].clear();
bck[i].clear();
vis[i] = 0;
}
for (int i = 0; i < X.size(); i++) {
int u = X[i], v = Y[i];
adj57[u].push_back(v);
adj57[v].push_back(u);
}
mmo = X.size();
init(0, 0);
dfs(0);
for (int i = 0; i < n; i++) {
ret[i] = findp(i);
}
return ret;
}
Compilation message
sphinx.cpp: In function 'std::vector<int> find_colours(int, std::vector<int>, std::vector<int>)':
sphinx.cpp:145:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
145 | for (int i = 0; i < X.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
336 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
#experiments: 1 |
2 |
Correct |
0 ms |
336 KB |
#experiments: 1 |
3 |
Partially correct |
1 ms |
336 KB |
Partially correct |
4 |
Partially correct |
1 ms |
336 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
336 KB |
Partially correct |
2 |
Correct |
1 ms |
336 KB |
#experiments: 1 |
3 |
Correct |
0 ms |
336 KB |
#experiments: 1 |
4 |
Partially correct |
1 ms |
336 KB |
Partially correct |
5 |
Partially correct |
1 ms |
336 KB |
Partially correct |
6 |
Partially correct |
1 ms |
336 KB |
Partially correct |
7 |
Partially correct |
1 ms |
336 KB |
Partially correct |
8 |
Partially correct |
1 ms |
336 KB |
Partially correct |
9 |
Partially correct |
1 ms |
336 KB |
Partially correct |
10 |
Partially correct |
1 ms |
336 KB |
Partially correct |
11 |
Partially correct |
1 ms |
336 KB |
Partially correct |
12 |
Partially correct |
1 ms |
336 KB |
Partially correct |
13 |
Partially correct |
1 ms |
336 KB |
Partially correct |
14 |
Partially correct |
2 ms |
336 KB |
Partially correct |
15 |
Partially correct |
8 ms |
336 KB |
Partially correct |
16 |
Partially correct |
6 ms |
336 KB |
Partially correct |
17 |
Partially correct |
7 ms |
520 KB |
Partially correct |
18 |
Partially correct |
7 ms |
512 KB |
Partially correct |
19 |
Partially correct |
11 ms |
336 KB |
Partially correct |
20 |
Partially correct |
7 ms |
516 KB |
Partially correct |
21 |
Partially correct |
9 ms |
336 KB |
Partially correct |
22 |
Partially correct |
4 ms |
336 KB |
Partially correct |
23 |
Partially correct |
4 ms |
336 KB |
Partially correct |
24 |
Partially correct |
4 ms |
484 KB |
Partially correct |
25 |
Partially correct |
4 ms |
336 KB |
Partially correct |
26 |
Partially correct |
1 ms |
336 KB |
Partially correct |
27 |
Partially correct |
1 ms |
336 KB |
Partially correct |
28 |
Partially correct |
1 ms |
336 KB |
Partially correct |
29 |
Partially correct |
3 ms |
480 KB |
Partially correct |
30 |
Partially correct |
4 ms |
336 KB |
Partially correct |
31 |
Partially correct |
7 ms |
336 KB |
Partially correct |
32 |
Partially correct |
8 ms |
336 KB |
Partially correct |
33 |
Partially correct |
2 ms |
336 KB |
Partially correct |
34 |
Partially correct |
8 ms |
500 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
#experiments: 1 |
2 |
Correct |
0 ms |
336 KB |
#experiments: 1 |
3 |
Partially correct |
1 ms |
336 KB |
Partially correct |
4 |
Partially correct |
1 ms |
336 KB |
Partially correct |
5 |
Partially correct |
1 ms |
336 KB |
Partially correct |
6 |
Partially correct |
1 ms |
336 KB |
Partially correct |
7 |
Partially correct |
1 ms |
336 KB |
Partially correct |
8 |
Partially correct |
1 ms |
336 KB |
Partially correct |
9 |
Partially correct |
1 ms |
336 KB |
Partially correct |
10 |
Partially correct |
1 ms |
336 KB |
Partially correct |
11 |
Partially correct |
1 ms |
336 KB |
Partially correct |
12 |
Partially correct |
1 ms |
336 KB |
Partially correct |
13 |
Partially correct |
7 ms |
336 KB |
Partially correct |
14 |
Partially correct |
6 ms |
592 KB |
Partially correct |
15 |
Partially correct |
6 ms |
592 KB |
Partially correct |
16 |
Partially correct |
7 ms |
592 KB |
Partially correct |
17 |
Partially correct |
6 ms |
336 KB |
Partially correct |
18 |
Partially correct |
8 ms |
848 KB |
Partially correct |
19 |
Partially correct |
8 ms |
336 KB |
Partially correct |
20 |
Partially correct |
9 ms |
528 KB |
Partially correct |
21 |
Partially correct |
7 ms |
508 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
#experiments: 1 |
2 |
Correct |
0 ms |
336 KB |
#experiments: 1 |
3 |
Partially correct |
1 ms |
336 KB |
Partially correct |
4 |
Partially correct |
1 ms |
336 KB |
Partially correct |
5 |
Partially correct |
2 ms |
336 KB |
Partially correct |
6 |
Partially correct |
8 ms |
336 KB |
Partially correct |
7 |
Partially correct |
6 ms |
336 KB |
Partially correct |
8 |
Partially correct |
7 ms |
520 KB |
Partially correct |
9 |
Partially correct |
7 ms |
512 KB |
Partially correct |
10 |
Partially correct |
11 ms |
336 KB |
Partially correct |
11 |
Partially correct |
7 ms |
516 KB |
Partially correct |
12 |
Partially correct |
9 ms |
336 KB |
Partially correct |
13 |
Partially correct |
181 ms |
1404 KB |
Partially correct |
14 |
Partially correct |
387 ms |
1656 KB |
Partially correct |
15 |
Partially correct |
561 ms |
1752 KB |
Partially correct |
16 |
Partially correct |
659 ms |
1512 KB |
Partially correct |
17 |
Partially correct |
742 ms |
1608 KB |
Partially correct |
18 |
Partially correct |
667 ms |
1944 KB |
Partially correct |
19 |
Partially correct |
640 ms |
2292 KB |
Partially correct |
20 |
Partially correct |
88 ms |
1400 KB |
Partially correct |
21 |
Partially correct |
491 ms |
2188 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
336 KB |
Partially correct |
2 |
Correct |
1 ms |
336 KB |
#experiments: 1 |
3 |
Correct |
0 ms |
336 KB |
#experiments: 1 |
4 |
Partially correct |
1 ms |
336 KB |
Partially correct |
5 |
Partially correct |
1 ms |
336 KB |
Partially correct |
6 |
Partially correct |
1 ms |
336 KB |
Partially correct |
7 |
Partially correct |
1 ms |
336 KB |
Partially correct |
8 |
Partially correct |
1 ms |
336 KB |
Partially correct |
9 |
Partially correct |
1 ms |
336 KB |
Partially correct |
10 |
Partially correct |
1 ms |
336 KB |
Partially correct |
11 |
Partially correct |
1 ms |
336 KB |
Partially correct |
12 |
Partially correct |
1 ms |
336 KB |
Partially correct |
13 |
Partially correct |
1 ms |
336 KB |
Partially correct |
14 |
Partially correct |
2 ms |
336 KB |
Partially correct |
15 |
Partially correct |
8 ms |
336 KB |
Partially correct |
16 |
Partially correct |
6 ms |
336 KB |
Partially correct |
17 |
Partially correct |
7 ms |
520 KB |
Partially correct |
18 |
Partially correct |
7 ms |
512 KB |
Partially correct |
19 |
Partially correct |
11 ms |
336 KB |
Partially correct |
20 |
Partially correct |
7 ms |
516 KB |
Partially correct |
21 |
Partially correct |
9 ms |
336 KB |
Partially correct |
22 |
Partially correct |
4 ms |
336 KB |
Partially correct |
23 |
Partially correct |
4 ms |
336 KB |
Partially correct |
24 |
Partially correct |
4 ms |
484 KB |
Partially correct |
25 |
Partially correct |
4 ms |
336 KB |
Partially correct |
26 |
Partially correct |
1 ms |
336 KB |
Partially correct |
27 |
Partially correct |
1 ms |
336 KB |
Partially correct |
28 |
Partially correct |
1 ms |
336 KB |
Partially correct |
29 |
Partially correct |
3 ms |
480 KB |
Partially correct |
30 |
Partially correct |
4 ms |
336 KB |
Partially correct |
31 |
Partially correct |
7 ms |
336 KB |
Partially correct |
32 |
Partially correct |
8 ms |
336 KB |
Partially correct |
33 |
Partially correct |
2 ms |
336 KB |
Partially correct |
34 |
Partially correct |
8 ms |
500 KB |
Partially correct |
35 |
Partially correct |
7 ms |
336 KB |
Partially correct |
36 |
Partially correct |
6 ms |
592 KB |
Partially correct |
37 |
Partially correct |
6 ms |
592 KB |
Partially correct |
38 |
Partially correct |
7 ms |
592 KB |
Partially correct |
39 |
Partially correct |
6 ms |
336 KB |
Partially correct |
40 |
Partially correct |
8 ms |
848 KB |
Partially correct |
41 |
Partially correct |
8 ms |
336 KB |
Partially correct |
42 |
Partially correct |
9 ms |
528 KB |
Partially correct |
43 |
Partially correct |
7 ms |
508 KB |
Partially correct |
44 |
Partially correct |
181 ms |
1404 KB |
Partially correct |
45 |
Partially correct |
387 ms |
1656 KB |
Partially correct |
46 |
Partially correct |
561 ms |
1752 KB |
Partially correct |
47 |
Partially correct |
659 ms |
1512 KB |
Partially correct |
48 |
Partially correct |
742 ms |
1608 KB |
Partially correct |
49 |
Partially correct |
667 ms |
1944 KB |
Partially correct |
50 |
Partially correct |
640 ms |
2292 KB |
Partially correct |
51 |
Partially correct |
88 ms |
1400 KB |
Partially correct |
52 |
Partially correct |
491 ms |
2188 KB |
Partially correct |
53 |
Partially correct |
58 ms |
548 KB |
Partially correct |
54 |
Partially correct |
76 ms |
584 KB |
Partially correct |
55 |
Partially correct |
71 ms |
600 KB |
Partially correct |
56 |
Partially correct |
121 ms |
840 KB |
Partially correct |
57 |
Partially correct |
333 ms |
1096 KB |
Partially correct |
58 |
Partially correct |
284 ms |
1140 KB |
Partially correct |
59 |
Partially correct |
274 ms |
884 KB |
Partially correct |
60 |
Partially correct |
305 ms |
1156 KB |
Partially correct |
61 |
Partially correct |
10 ms |
336 KB |
Partially correct |
62 |
Partially correct |
6 ms |
512 KB |
Partially correct |
63 |
Partially correct |
10 ms |
336 KB |
Partially correct |
64 |
Partially correct |
84 ms |
584 KB |
Partially correct |
65 |
Partially correct |
107 ms |
592 KB |
Partially correct |
66 |
Partially correct |
84 ms |
844 KB |
Partially correct |
67 |
Partially correct |
96 ms |
848 KB |
Partially correct |
68 |
Partially correct |
98 ms |
868 KB |
Partially correct |
69 |
Partially correct |
99 ms |
840 KB |
Partially correct |
70 |
Partially correct |
94 ms |
612 KB |
Partially correct |
71 |
Partially correct |
117 ms |
864 KB |
Partially correct |
72 |
Partially correct |
37 ms |
592 KB |
Partially correct |
73 |
Partially correct |
55 ms |
336 KB |
Partially correct |
74 |
Partially correct |
75 ms |
1080 KB |
Partially correct |
75 |
Partially correct |
79 ms |
592 KB |
Partially correct |
76 |
Partially correct |
91 ms |
596 KB |
Partially correct |
77 |
Partially correct |
99 ms |
604 KB |
Partially correct |
78 |
Partially correct |
128 ms |
624 KB |
Partially correct |
79 |
Partially correct |
111 ms |
636 KB |
Partially correct |
80 |
Partially correct |
139 ms |
636 KB |
Partially correct |
81 |
Partially correct |
147 ms |
852 KB |
Partially correct |
82 |
Partially correct |
163 ms |
840 KB |
Partially correct |
83 |
Partially correct |
576 ms |
1492 KB |
Partially correct |
84 |
Partially correct |
790 ms |
1608 KB |
Partially correct |
85 |
Partially correct |
31 ms |
708 KB |
Partially correct |
86 |
Partially correct |
219 ms |
1364 KB |
Partially correct |