# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
466437 | prvocislo | Chameleon's Love (JOI20_chameleon) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "chameleon.h"
#include <vector>
#include <iostream>
using namespace std;
const int maxn = 505;
vector<int> g[maxn * 2];
vector<pair<int, int>> v;
bool vis[maxn];
int query(int x, vector<int> a)
{
a.push_back(x);
return Query(a);
}
void find_edges(int x, const vector<int> &a)
{
if (!a.size()) return;
if (a.size() == 1)
{
//cout << x << " " << a[0] << "\n";
if (query(x, a) == 1) g[x].push_back(a[0]), g[a[0]].push_back(x);
return;
}
vector<int> a1(a.begin(), a.begin() + a.size() / 2), a2(a.begin() + a.size() / 2, a.end());
int c1 = query(x, a1), c2 = query(x, a2);
if (c1 < a1.size() + 1) find_edges(x, a1);
if (c2 < a2.size() + 1) find_edges(x, a2);
}
void dfs(int u, int c, vector<vector<int> >& k)
{
k[c].push_back(u), vis[u] = true;
for (int v : g[u]) if (!vis[v]) dfs(v, c ^ 1, k);
}
void Solve(int n)
{
for (int i = 2; i <= 2 * n; i++)
{
vector<vector<int> > k(2);
fill(vis, vis + maxn, false);
for (int j = 1; j < i; j++) if (!vis[j]) dfs(j, 0, k);
find_edges(i, k[0]);
find_edges(i, k[1]);
}
for (int i = 1; i <= 2 * n; i++) if (g[i].size() == 3)
{
for (int j = 0; j < 3; j++) for (int k = 0; k < j; k++)
{
int c = query(i, { g[i][j], g[i][k] });
if (c == 1) v.push_back({ i, g[i][3 ^ j ^ k] });
}
}
for (const pair<int, int>& i : v)
{
g[i.first].erase(find(g[i.first].begin(), g[i.first].end(), i.second));
g[i.second].erase(find(g[i.second].begin(), g[i.second].end(), i.first));
}
for (int i = 1; i <= 2 * n; i++) if (g[i][0] > i)
{
Answer(i, g[i][0]);
}
}