#include "chameleon.h"
#include <vector>
#include <cassert>
#include <iostream>
#define MAXN 1005
using namespace std;
vector <int> adj[MAXN];
vector <int> M, F;
int Love[MAXN], vis[MAXN];
void findEdge(int i, vector<int> IS) {
IS.push_back(i);
if (IS.size() == 1 || Query(IS) == IS.size()) {return;}
if (IS.size() == 2) {
adj[i].push_back(IS[0]);
adj[IS[0]].push_back(i);
} 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]);}
}
findEdge(i, L);
findEdge(i, R);
}
}
void dfs(int u, int t, bool c) {
vis[u] = t;
if (c) {M.push_back(u);}
else {F.push_back(u);}
for (int v: adj[u]) {
if (vis[v] != t) {dfs(v, t, c^1);}
}
}
void bipartite(int t) {
M.clear();
F.clear();
for (int i=1; i<t; i++) {
if (vis[i] != t) {dfs(i,t,0);}
}
}
void Solve(int N) {
for (int i=1; i<=2*N; i++) {
bipartite(i);
findEdge(i, M);
findEdge(i, F);
}
for (int i=1; i<=2*N; i++) {
assert(adj[i].size() == 1 || adj[i].size() == 3);
if (adj[i].size() != 3) {
if (adj[i][0] > i) {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 (Query(Ask) == 1) {
Love[i] = adj[i][j];
break;
}
}
}
bipartite(2*N+1);
for (int f: F) {
for (int m: adj[f]) {
if (Love[m] != f && Love[f] != m && adj[f].size() == 3) {
Answer(f,m);
}
}
}
}
Compilation message
chameleon.cpp: In function 'void findEdge(int, std::vector<int>)':
chameleon.cpp:13:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (IS.size() == 1 || Query(IS) == IS.size()) {return;}
~~~~~~~~~~^~~~~~~~~~~~
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 |
37 ms |
384 KB |
Output is correct |
4 |
Correct |
38 ms |
384 KB |
Output is correct |
5 |
Correct |
39 ms |
384 KB |
Output is correct |
6 |
Correct |
37 ms |
384 KB |
Output is correct |
7 |
Correct |
36 ms |
384 KB |
Output is correct |
8 |
Correct |
36 ms |
384 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 |
Incorrect |
4 ms |
384 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
4 ms |
384 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Incorrect |
56 ms |
504 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
37 ms |
384 KB |
Output is correct |
4 |
Correct |
38 ms |
384 KB |
Output is correct |
5 |
Correct |
39 ms |
384 KB |
Output is correct |
6 |
Correct |
37 ms |
384 KB |
Output is correct |
7 |
Correct |
36 ms |
384 KB |
Output is correct |
8 |
Correct |
36 ms |
384 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 |
Incorrect |
4 ms |
384 KB |
Wrong Answer [7] |
13 |
Halted |
0 ms |
0 KB |
- |