#include <bits/stdc++.h>
#include "sphinx.h"
using namespace std;
int pr2[251];
int find2(int x){
if(x==pr2[x])return x;
return pr2[x] = find2(pr2[x]);
}
void mergegroup2(int a,int b){
a = find2(a);
b = find2(b);
if(a==b)return ;
pr2[a] = b;
}
int pr[251];
vector<int> adjj[251],nadj[251];
int find(int x){
if(x==pr[x])return x;
return pr[x] = find(pr[x]);
}
bool mergegroup(int a,int b){
a = find(a);
b = find(b);
if(a==b)return 0;
pr[a] = b;
return 1;
}
vector<int> even,odd;
int VIS[251];
void dfs(int i,int dep){
VIS[i] =1 ;
if(dep)even.push_back(i);
else odd.push_back(i);
for(auto j:nadj[i]){
if(!VIS[j])dfs(j,dep^1);
}
}
vector<int> find_colours(int n,vector<int> X,vector<int> Y){
for(int i = 0;i<X.size();i++){
adjj[X[i]].push_back(Y[i]);
adjj[Y[i]].push_back(X[i]);
}
int d = 0;
for(int i = 0;i<n;i++){
pr2[i] = i;
}
for(int i = n-1;i>=0;i--){
int ans = 0;
while(ans!=-1){
vector<int> v;
int vis[n] = {0};
for(auto j:adjj[i]){
if(j>i&&vis[find2(j)]==0&&find2(j)!=find2(i)){
v.push_back(j);
vis[find2(j)] = 1;
}
}
int sz = v.size();
int l = 0 , r = sz-1;
ans = -1;
int ss = 0;
while(l<=r){
int mid = 0;
if(ss==0){
mid = r;
ss = 1;
}else if(ss==1){
ss = 2;
l = 0 , r = sz-1;
mid = (l+r)/2;
}else{
mid = (l+r)/2;
}
vector<int> e(n,n);
e[i] = -1;
for(int j = 0;j<=mid;j++){
e[v[j]] = -1;
}
int cnt = 0;
for(int j = 0;j<n;j++){
if(e[j]==-1){
pr[j] = j;cnt++;
}else {
pr[j] = j;cnt++;
}
}
for(int j = 0;j<X.size();j++){
if(e[X[j]]==-1&&e[Y[j]]==-1){
if(X[j]==i||Y[j]==i)continue;
if(find2(X[j])==find2(Y[j]))cnt-=mergegroup(X[j],Y[j]);
}else if(e[X[j]]==n&&e[Y[j]]==n){
cnt-=mergegroup(X[j],Y[j]);
}
}
if(cnt==perform_experiment(e)){
l = mid+1;
}else {
ans = mid;
r = mid-1;
}
}
if(ans!=-1){
mergegroup2(i,v[ans]);
}
}
}
vector<int> V[n];
for(int i = 0;i<n;i++){
V[find2(i)].push_back(i);
}
for(int i = 0;i<X.size();i++){
if(find2(X[i])!=find2(Y[i])){
nadj[find2(X[i])].push_back(find2(Y[i]));
nadj[find2(Y[i])].push_back(find2(X[i]));
}
}
dfs(find2(0),0);
if(even.size()+odd.size()==1){
for(int i = 0;i<n;i++){
vector<int> e(n,i);
e[0] = -1;
if(perform_experiment(e)==1){
vector<int> na(n,i);
return na;
}
}
}
int in[n] = {0};
for(int i = 0;i<n;i++){
{
vector<int> lol;
for(auto j:even){
if(in[j]==0){
lol.push_back(j);
}
}
int ans = 0;
while(ans!=-1){
int sz = lol.size();
int l = ans , r = sz-1;
int org = ans;
ans = -1;
int ss = 0;
while(l<=r){
int mid = 0;
if(ss==0){
mid = r;
ss = 1;
}else if(ss==1){
ss = 2;
l = org , r = sz-1;
mid = (l+r)/2;
}else{
mid = (l+r)/2;
}
vector<int> e(n,i);
int cnt = 0;
for(int j = 0;j<n;j++){
if(e[j]==-1){
pr[j] = j;cnt++;
}else {
pr[j] = j;cnt++;
}
}
for(int j = org;j<=mid;j++){
for(auto w:V[lol[j]]){
e[w] = -1;
}
}
for(int j = 0;j<X.size();j++){
if(e[X[j]]==-1&&e[Y[j]]==-1){
if(find2(X[j])==find2(Y[j]))cnt-=mergegroup(X[j],Y[j]);
}else if(e[X[j]]==i&&e[Y[j]]==i){
cnt-=mergegroup(X[j],Y[j]);
}
}
if(cnt==perform_experiment(e)){
l = mid+1;
}else {
ans = mid;
r = mid-1;
}
}
if(ans==-1){
break;
}
in[lol[ans]] = i+1;
ans++;
}
}
swap(even,odd);
{
vector<int> lol;
for(auto j:even){
if(in[j]==0){
lol.push_back(j);
}
}
int ans = 0;
while(ans!=-1){
int sz = lol.size();
int l = ans , r = sz-1;
int org = ans;
ans = -1;
int ss = 0;
while(l<=r){
int mid = 0;
if(ss==0){
mid = r;
ss = 1;
}else if(ss==1){
ss = 2;
l = org , r = sz-1;
mid = (l+r)/2;
}else{
mid = (l+r)/2;
}
vector<int> e(n,i);
int cnt = 0;
for(int j = 0;j<n;j++){
if(e[j]==-1){
pr[j] = j;cnt++;
}else {
pr[j] = j;cnt++;
}
}
for(int j = org;j<=mid;j++){
for(auto w:V[lol[j]]){
e[w] = -1;
}
}
for(int j = 0;j<X.size();j++){
if(e[X[j]]==-1&&e[Y[j]]==-1){
if(find2(X[j])==find2(Y[j]))cnt-=mergegroup(X[j],Y[j]);
}else if(e[X[j]]==i&&e[Y[j]]==i){
cnt-=mergegroup(X[j],Y[j]);
}
}
if(cnt==perform_experiment(e)){
l = mid+1;
}else {
ans = mid;
r = mid-1;
}
}
if(ans==-1){
break;
}
in[lol[ans]] = i+1;
ans++;
}
}
}
vector<int> col(n,0);
for(int i = 0;i<n;i++){
col[i] = in[find2(i)]-1;
}
return col;
}
Compilation message
sphinx.cpp: In function 'std::vector<int> find_colours(int, std::vector<int>, std::vector<int>)':
sphinx.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i = 0;i<X.size();i++){
| ~^~~~~~~~~
sphinx.cpp:88:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int j = 0;j<X.size();j++){
| ~^~~~~~~~~
sphinx.cpp:112:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for(int i = 0;i<X.size();i++){
| ~^~~~~~~~~
sphinx.cpp:171:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
171 | for(int j = 0;j<X.size();j++){
| ~^~~~~~~~~
sphinx.cpp:233:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
233 | for(int j = 0;j<X.size();j++){
| ~^~~~~~~~~
sphinx.cpp:44:9: warning: unused variable 'd' [-Wunused-variable]
44 | int d = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
#experiments: 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
#experiments: 2 |
2 |
Correct |
1 ms |
336 KB |
#experiments: 4 |
3 |
Correct |
1 ms |
336 KB |
#experiments: 4 |
4 |
Correct |
1 ms |
336 KB |
#experiments: 3 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
#experiments: 8 |
2 |
Correct |
1 ms |
336 KB |
#experiments: 2 |
3 |
Correct |
1 ms |
336 KB |
#experiments: 4 |
4 |
Correct |
1 ms |
336 KB |
#experiments: 4 |
5 |
Correct |
1 ms |
336 KB |
#experiments: 3 |
6 |
Correct |
2 ms |
336 KB |
#experiments: 74 |
7 |
Correct |
2 ms |
336 KB |
#experiments: 104 |
8 |
Correct |
2 ms |
336 KB |
#experiments: 147 |
9 |
Correct |
2 ms |
336 KB |
#experiments: 139 |
10 |
Correct |
2 ms |
336 KB |
#experiments: 154 |
11 |
Correct |
3 ms |
508 KB |
#experiments: 190 |
12 |
Correct |
4 ms |
336 KB |
#experiments: 353 |
13 |
Correct |
4 ms |
336 KB |
#experiments: 364 |
14 |
Correct |
2 ms |
336 KB |
#experiments: 64 |
15 |
Correct |
5 ms |
592 KB |
#experiments: 275 |
16 |
Correct |
5 ms |
336 KB |
#experiments: 312 |
17 |
Correct |
6 ms |
336 KB |
#experiments: 328 |
18 |
Correct |
9 ms |
500 KB |
#experiments: 362 |
19 |
Correct |
6 ms |
336 KB |
#experiments: 355 |
20 |
Correct |
6 ms |
336 KB |
#experiments: 362 |
21 |
Correct |
6 ms |
336 KB |
#experiments: 364 |
22 |
Correct |
4 ms |
336 KB |
#experiments: 245 |
23 |
Correct |
5 ms |
336 KB |
#experiments: 244 |
24 |
Correct |
6 ms |
336 KB |
#experiments: 261 |
25 |
Correct |
5 ms |
336 KB |
#experiments: 307 |
26 |
Correct |
3 ms |
336 KB |
#experiments: 249 |
27 |
Correct |
5 ms |
336 KB |
#experiments: 300 |
28 |
Correct |
4 ms |
336 KB |
#experiments: 333 |
29 |
Correct |
4 ms |
336 KB |
#experiments: 279 |
30 |
Correct |
6 ms |
336 KB |
#experiments: 344 |
31 |
Correct |
6 ms |
336 KB |
#experiments: 336 |
32 |
Correct |
7 ms |
496 KB |
#experiments: 358 |
33 |
Correct |
2 ms |
336 KB |
#experiments: 83 |
34 |
Correct |
8 ms |
336 KB |
#experiments: 365 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
#experiments: 2 |
2 |
Correct |
1 ms |
336 KB |
#experiments: 4 |
3 |
Correct |
1 ms |
336 KB |
#experiments: 4 |
4 |
Correct |
1 ms |
336 KB |
#experiments: 3 |
5 |
Correct |
2 ms |
336 KB |
#experiments: 74 |
6 |
Correct |
2 ms |
336 KB |
#experiments: 104 |
7 |
Correct |
2 ms |
336 KB |
#experiments: 147 |
8 |
Correct |
2 ms |
336 KB |
#experiments: 139 |
9 |
Correct |
2 ms |
336 KB |
#experiments: 154 |
10 |
Correct |
3 ms |
508 KB |
#experiments: 190 |
11 |
Correct |
4 ms |
336 KB |
#experiments: 353 |
12 |
Correct |
4 ms |
336 KB |
#experiments: 364 |
13 |
Correct |
8 ms |
336 KB |
#experiments: 368 |
14 |
Correct |
16 ms |
468 KB |
#experiments: 710 |
15 |
Correct |
23 ms |
336 KB |
#experiments: 701 |
16 |
Correct |
15 ms |
336 KB |
#experiments: 724 |
17 |
Correct |
22 ms |
468 KB |
#experiments: 916 |
18 |
Correct |
31 ms |
592 KB |
#experiments: 1277 |
19 |
Correct |
40 ms |
504 KB |
#experiments: 1974 |
20 |
Correct |
9 ms |
336 KB |
#experiments: 383 |
21 |
Correct |
53 ms |
336 KB |
#experiments: 2390 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
#experiments: 2 |
2 |
Correct |
1 ms |
336 KB |
#experiments: 4 |
3 |
Correct |
1 ms |
336 KB |
#experiments: 4 |
4 |
Correct |
1 ms |
336 KB |
#experiments: 3 |
5 |
Correct |
2 ms |
336 KB |
#experiments: 64 |
6 |
Correct |
5 ms |
592 KB |
#experiments: 275 |
7 |
Correct |
5 ms |
336 KB |
#experiments: 312 |
8 |
Correct |
6 ms |
336 KB |
#experiments: 328 |
9 |
Correct |
9 ms |
500 KB |
#experiments: 362 |
10 |
Correct |
6 ms |
336 KB |
#experiments: 355 |
11 |
Correct |
6 ms |
336 KB |
#experiments: 362 |
12 |
Correct |
6 ms |
336 KB |
#experiments: 364 |
13 |
Correct |
202 ms |
1204 KB |
#experiments: 1174 |
14 |
Correct |
258 ms |
1456 KB |
#experiments: 1649 |
15 |
Correct |
297 ms |
1612 KB |
#experiments: 1862 |
16 |
Correct |
347 ms |
1584 KB |
#experiments: 2132 |
17 |
Correct |
358 ms |
1576 KB |
#experiments: 2293 |
18 |
Correct |
343 ms |
1716 KB |
#experiments: 2374 |
19 |
Correct |
338 ms |
1352 KB |
#experiments: 2399 |
20 |
Correct |
44 ms |
1104 KB |
#experiments: 309 |
21 |
Correct |
340 ms |
1352 KB |
#experiments: 2403 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
#experiments: 8 |
2 |
Correct |
1 ms |
336 KB |
#experiments: 2 |
3 |
Correct |
1 ms |
336 KB |
#experiments: 4 |
4 |
Correct |
1 ms |
336 KB |
#experiments: 4 |
5 |
Correct |
1 ms |
336 KB |
#experiments: 3 |
6 |
Correct |
2 ms |
336 KB |
#experiments: 74 |
7 |
Correct |
2 ms |
336 KB |
#experiments: 104 |
8 |
Correct |
2 ms |
336 KB |
#experiments: 147 |
9 |
Correct |
2 ms |
336 KB |
#experiments: 139 |
10 |
Correct |
2 ms |
336 KB |
#experiments: 154 |
11 |
Correct |
3 ms |
508 KB |
#experiments: 190 |
12 |
Correct |
4 ms |
336 KB |
#experiments: 353 |
13 |
Correct |
4 ms |
336 KB |
#experiments: 364 |
14 |
Correct |
2 ms |
336 KB |
#experiments: 64 |
15 |
Correct |
5 ms |
592 KB |
#experiments: 275 |
16 |
Correct |
5 ms |
336 KB |
#experiments: 312 |
17 |
Correct |
6 ms |
336 KB |
#experiments: 328 |
18 |
Correct |
9 ms |
500 KB |
#experiments: 362 |
19 |
Correct |
6 ms |
336 KB |
#experiments: 355 |
20 |
Correct |
6 ms |
336 KB |
#experiments: 362 |
21 |
Correct |
6 ms |
336 KB |
#experiments: 364 |
22 |
Correct |
4 ms |
336 KB |
#experiments: 245 |
23 |
Correct |
5 ms |
336 KB |
#experiments: 244 |
24 |
Correct |
6 ms |
336 KB |
#experiments: 261 |
25 |
Correct |
5 ms |
336 KB |
#experiments: 307 |
26 |
Correct |
3 ms |
336 KB |
#experiments: 249 |
27 |
Correct |
5 ms |
336 KB |
#experiments: 300 |
28 |
Correct |
4 ms |
336 KB |
#experiments: 333 |
29 |
Correct |
4 ms |
336 KB |
#experiments: 279 |
30 |
Correct |
6 ms |
336 KB |
#experiments: 344 |
31 |
Correct |
6 ms |
336 KB |
#experiments: 336 |
32 |
Correct |
7 ms |
496 KB |
#experiments: 358 |
33 |
Correct |
2 ms |
336 KB |
#experiments: 83 |
34 |
Correct |
8 ms |
336 KB |
#experiments: 365 |
35 |
Correct |
8 ms |
336 KB |
#experiments: 368 |
36 |
Correct |
16 ms |
468 KB |
#experiments: 710 |
37 |
Correct |
23 ms |
336 KB |
#experiments: 701 |
38 |
Correct |
15 ms |
336 KB |
#experiments: 724 |
39 |
Correct |
22 ms |
468 KB |
#experiments: 916 |
40 |
Correct |
31 ms |
592 KB |
#experiments: 1277 |
41 |
Correct |
40 ms |
504 KB |
#experiments: 1974 |
42 |
Correct |
9 ms |
336 KB |
#experiments: 383 |
43 |
Correct |
53 ms |
336 KB |
#experiments: 2390 |
44 |
Correct |
202 ms |
1204 KB |
#experiments: 1174 |
45 |
Correct |
258 ms |
1456 KB |
#experiments: 1649 |
46 |
Correct |
297 ms |
1612 KB |
#experiments: 1862 |
47 |
Correct |
347 ms |
1584 KB |
#experiments: 2132 |
48 |
Correct |
358 ms |
1576 KB |
#experiments: 2293 |
49 |
Correct |
343 ms |
1716 KB |
#experiments: 2374 |
50 |
Correct |
338 ms |
1352 KB |
#experiments: 2399 |
51 |
Correct |
44 ms |
1104 KB |
#experiments: 309 |
52 |
Correct |
340 ms |
1352 KB |
#experiments: 2403 |
53 |
Correct |
66 ms |
500 KB |
#experiments: 1878 |
54 |
Correct |
73 ms |
544 KB |
#experiments: 1810 |
55 |
Correct |
87 ms |
552 KB |
#experiments: 1838 |
56 |
Correct |
81 ms |
572 KB |
#experiments: 1786 |
57 |
Correct |
156 ms |
808 KB |
#experiments: 1685 |
58 |
Correct |
164 ms |
788 KB |
#experiments: 1819 |
59 |
Correct |
160 ms |
788 KB |
#experiments: 1683 |
60 |
Correct |
199 ms |
840 KB |
#experiments: 2115 |
61 |
Correct |
43 ms |
472 KB |
#experiments: 1859 |
62 |
Correct |
59 ms |
336 KB |
#experiments: 2043 |
63 |
Correct |
56 ms |
336 KB |
#experiments: 2271 |
64 |
Correct |
67 ms |
336 KB |
#experiments: 1727 |
65 |
Correct |
72 ms |
528 KB |
#experiments: 1814 |
66 |
Correct |
90 ms |
548 KB |
#experiments: 1829 |
67 |
Correct |
88 ms |
552 KB |
#experiments: 1924 |
68 |
Correct |
89 ms |
588 KB |
#experiments: 1881 |
69 |
Correct |
86 ms |
584 KB |
#experiments: 1888 |
70 |
Correct |
87 ms |
568 KB |
#experiments: 1902 |
71 |
Correct |
99 ms |
564 KB |
#experiments: 1801 |
72 |
Correct |
70 ms |
512 KB |
#experiments: 1939 |
73 |
Correct |
61 ms |
336 KB |
#experiments: 1815 |
74 |
Correct |
98 ms |
520 KB |
#experiments: 1920 |
75 |
Correct |
90 ms |
544 KB |
#experiments: 1732 |
76 |
Correct |
86 ms |
556 KB |
#experiments: 1875 |
77 |
Correct |
76 ms |
596 KB |
#experiments: 1765 |
78 |
Correct |
86 ms |
592 KB |
#experiments: 1798 |
79 |
Correct |
85 ms |
596 KB |
#experiments: 1750 |
80 |
Correct |
109 ms |
592 KB |
#experiments: 1835 |
81 |
Correct |
97 ms |
596 KB |
#experiments: 1921 |
82 |
Correct |
146 ms |
628 KB |
#experiments: 2312 |
83 |
Correct |
322 ms |
1320 KB |
#experiments: 2019 |
84 |
Correct |
566 ms |
1444 KB |
#experiments: 2381 |
85 |
Correct |
21 ms |
648 KB |
#experiments: 470 |
86 |
Correct |
236 ms |
752 KB |
#experiments: 2397 |