#include "chameleon.h"
#include <vector>
#define MAXN 1005
using namespace std;
vector <int> adj[MAXN];
vector <int> M, F;
int Num, Love[MAXN], vis[MAXN];
bool findEdge(int i, vector<int> IS, bool b) {
IS.push_back(i);
if (Num == 3 || IS.size() == 1 || (!b && Query(IS) == IS.size())) {return(false);}
if (IS.size() == 2) {
adj[i].push_back(IS[0]);
adj[IS[0]].push_back(i);
Num++;
return(true);
} else {
IS.pop_back();
vector <int> L, R;
int mid = (IS.size() - 1)/2;
for (int i=0; i < IS.size(); i++) {
if (i <= mid) {L.push_back(IS[i]);}
else {R.push_back(IS[i]);}
}
if (!findEdge(i, L, 0)) {
findEdge(i, R, 1);
} else {
findEdge(i, R, 0);
}
return(true);
}
}
void dfs(int u, int t, bool c, bool k) {
vis[u] = t;
if (c && (adj[u].size() != 3 || k)) {M.push_back(u);}
else if (adj[u].size() != 3 || k) {F.push_back(u);}
for (int v: adj[u]) {
if (vis[v] != t) {dfs(v, t, c^1,k);}
}
}
void bipartite(int t, bool k) {
M.clear();
F.clear();
for (int i=1; i<t; i++) {
if (vis[i] != t) {dfs(i,t,0,k);}
}
}
void Solve(int N) {
for (int i=1; i<=2*N; i++) {
Num = 0;
bipartite(i,0);
findEdge(i, M, 0);
findEdge(i, F, 0);
}
for (int i=1; i<=2*N; i++) {
if (adj[i].size() != 3) {
if (adj[i][0] > i || adj[adj[i][0]].size() == 3) {Answer(i, adj[i][0]);}
continue;
}
for (int j=0; j<3; j++) {
vector <int> Ask;
Ask.push_back(i);
for (int k=0; k<3; k++) {
if (j != k) {Ask.push_back(adj[i][k]);}
}
if (j == 2 || Query(Ask) == 1) {
Love[i] = adj[i][j];
break;
}
}
}
bipartite(2*N+1, 1);
for (int f: F) {
for (int m: adj[f]) {
if (Love[m] != f && Love[f] != m && adj[f].size() == 3 && adj[m].size() == 3) {
Answer(f,m);
}
}
}
}
Compilation message
chameleon.cpp: In function 'bool findEdge(int, std::vector<int>, bool)':
chameleon.cpp:11:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (Num == 3 || IS.size() == 1 || (!b && Query(IS) == IS.size())) {return(false);}
~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp:21:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i < IS.size(); i++) {
~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
31 ms |
384 KB |
Output is correct |
4 |
Correct |
32 ms |
384 KB |
Output is correct |
5 |
Correct |
31 ms |
384 KB |
Output is correct |
6 |
Correct |
31 ms |
384 KB |
Output is correct |
7 |
Correct |
31 ms |
384 KB |
Output is correct |
8 |
Correct |
41 ms |
512 KB |
Output is correct |
9 |
Correct |
40 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
52 ms |
480 KB |
Output is correct |
4 |
Correct |
48 ms |
384 KB |
Output is correct |
5 |
Correct |
47 ms |
504 KB |
Output is correct |
6 |
Correct |
47 ms |
504 KB |
Output is correct |
7 |
Correct |
46 ms |
384 KB |
Output is correct |
8 |
Correct |
47 ms |
384 KB |
Output is correct |
9 |
Correct |
48 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
31 ms |
384 KB |
Output is correct |
4 |
Correct |
32 ms |
384 KB |
Output is correct |
5 |
Correct |
31 ms |
384 KB |
Output is correct |
6 |
Correct |
31 ms |
384 KB |
Output is correct |
7 |
Correct |
31 ms |
384 KB |
Output is correct |
8 |
Correct |
41 ms |
512 KB |
Output is correct |
9 |
Correct |
40 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
52 ms |
480 KB |
Output is correct |
31 |
Correct |
48 ms |
384 KB |
Output is correct |
32 |
Correct |
47 ms |
504 KB |
Output is correct |
33 |
Correct |
47 ms |
504 KB |
Output is correct |
34 |
Correct |
46 ms |
384 KB |
Output is correct |
35 |
Correct |
47 ms |
384 KB |
Output is correct |
36 |
Correct |
48 ms |
512 KB |
Output is correct |
37 |
Correct |
45 ms |
384 KB |
Output is correct |
38 |
Correct |
32 ms |
512 KB |
Output is correct |
39 |
Correct |
46 ms |
384 KB |
Output is correct |
40 |
Correct |
47 ms |
384 KB |
Output is correct |
41 |
Correct |
46 ms |
448 KB |
Output is correct |
42 |
Correct |
32 ms |
432 KB |
Output is correct |
43 |
Correct |
47 ms |
504 KB |
Output is correct |
44 |
Correct |
46 ms |
384 KB |
Output is correct |
45 |
Correct |
45 ms |
504 KB |
Output is correct |