#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define pb push_back
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#ifdef BALBIT
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){cerr<<x<<", "; _do(y...);}
#define bug(...) cerr<<"#"<<__LINE__<<"- "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
namespace {
const int maxn = 1000+3;
//int variable_example = 1;
vector<int> g[maxn]; // currently known graph
vector<int> p0, p1; // parts of bipartite graph
int col[maxn];
void bpdfs(int v, int c) {
col[v] = c;
for (int u : g[v]) {
if (col[u] == -1) {
bpdfs(u, c^1);
}
}
}
int QQ(vector<int> x) {
for (int &y : x) ++y;
return Query(x);
}
bool add(vector<int> &p, int v, int l, int r, bool def) {
if (l > r) return 0;
if (def == 0) {
vector<int> aa;
for (int i = l; i<=r; ++i) aa.pb(p[i]);
aa.pb(v);
int gt = QQ(aa);
if (gt < SZ(aa) ) {
// there is a love pair or an orig color pair
def = 1;
}
}
if (!def) return 0;
if (l == r) {
//here!
int u = p[l];
g[u].pb(v); g[v].pb(u);
return 1;
}
int mid = (l+r)/2;
bool getleft = add(p, v, l, mid, 0);
add(p, v, mid+1, r, !getleft); // if getleft found nothing, there has to be smth in the right
return 1;
}
set<pii> ban;
void bye(int a, int b) {
if (a > b) swap(a,b);
ban.insert({a,b});
}
} // namespace
void Solve(int n) {
REP(i, 2*n) {
memset(col, -1, sizeof col);
p0.clear(); p1.clear();
REP(j, i) {
if (col[j] == -1) {
bpdfs(j, 0);
}
}
REP(j,i) {
if (SZ(g[j]) == 3) continue;
(col[j]?p1:p0).pb(j);
}
add(p0, i, 0, SZ(p0)-1, 0);
add(p1, i, 0, SZ(p1)-1, 0);
}
// REP(i,n*2) {
// for (int v : g[i]) {
// bug(i+1, v+1);
// }
// }
REP(i,n*2) {
if (SZ(g[i]) == 1) continue;
assert(SZ(g[i]) <= 3);
random_shuffle(ALL(g[i]));
int no2 = QQ({i, g[i][0], g[i][1]});
if (no2 == 1) {
bye(i, g[i][2]); continue;
}
int no1 = QQ({i, g[i][0], g[i][2]});
if (no1 == 1) {
bye(i, g[i][1]); continue;
}
bye(i, g[i][0]);
}
vector<pii> re;
REP(i,n*2) {
for (int u : g[i]) {
if (u < i && !ban.count({u,i})) {
re.pb({u,i});
bug(u+1, i+1);
}
}
}
for (pii p : re) {
Answer(p.f+1, p.s+1);
}
}
/*
4
1 0 1 0 0 1 1 0
4 4 1 2 1 2 3 3
4 3 8 7 6 5 2 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
27 ms |
388 KB |
Output is correct |
4 |
Correct |
24 ms |
456 KB |
Output is correct |
5 |
Correct |
23 ms |
392 KB |
Output is correct |
6 |
Correct |
23 ms |
384 KB |
Output is correct |
7 |
Correct |
22 ms |
400 KB |
Output is correct |
8 |
Correct |
22 ms |
408 KB |
Output is correct |
9 |
Correct |
23 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
38 ms |
396 KB |
Output is correct |
4 |
Correct |
37 ms |
420 KB |
Output is correct |
5 |
Correct |
35 ms |
396 KB |
Output is correct |
6 |
Correct |
34 ms |
448 KB |
Output is correct |
7 |
Correct |
37 ms |
392 KB |
Output is correct |
8 |
Correct |
36 ms |
384 KB |
Output is correct |
9 |
Correct |
38 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
27 ms |
388 KB |
Output is correct |
4 |
Correct |
24 ms |
456 KB |
Output is correct |
5 |
Correct |
23 ms |
392 KB |
Output is correct |
6 |
Correct |
23 ms |
384 KB |
Output is correct |
7 |
Correct |
22 ms |
400 KB |
Output is correct |
8 |
Correct |
22 ms |
408 KB |
Output is correct |
9 |
Correct |
23 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
328 KB |
Output is correct |
11 |
Correct |
0 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
0 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
328 KB |
Output is correct |
17 |
Correct |
0 ms |
328 KB |
Output is correct |
18 |
Correct |
0 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
328 KB |
Output is correct |
27 |
Correct |
1 ms |
328 KB |
Output is correct |
28 |
Correct |
0 ms |
328 KB |
Output is correct |
29 |
Correct |
1 ms |
328 KB |
Output is correct |
30 |
Correct |
38 ms |
396 KB |
Output is correct |
31 |
Correct |
37 ms |
420 KB |
Output is correct |
32 |
Correct |
35 ms |
396 KB |
Output is correct |
33 |
Correct |
34 ms |
448 KB |
Output is correct |
34 |
Correct |
37 ms |
392 KB |
Output is correct |
35 |
Correct |
36 ms |
384 KB |
Output is correct |
36 |
Correct |
38 ms |
384 KB |
Output is correct |
37 |
Correct |
39 ms |
400 KB |
Output is correct |
38 |
Correct |
25 ms |
400 KB |
Output is correct |
39 |
Correct |
37 ms |
396 KB |
Output is correct |
40 |
Correct |
36 ms |
448 KB |
Output is correct |
41 |
Correct |
35 ms |
396 KB |
Output is correct |
42 |
Correct |
22 ms |
328 KB |
Output is correct |
43 |
Correct |
38 ms |
376 KB |
Output is correct |
44 |
Correct |
36 ms |
388 KB |
Output is correct |
45 |
Correct |
50 ms |
388 KB |
Output is correct |