#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
using ll = int;
using ull = unsigned long long;
using lld = long double;
using ii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
using vpll = vector<pll>;
using vlld = vector<lld>;
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define gcd(a,b) __gcd(a,b)
#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fls cout.flush()
#define fore(i, l, r) for (auto i = l; i < r; i++)
#define fo(i, n) fore (i, 0, n)
#define forex(i, r, l) for (auto i = r-1; i >= l; i--)
#define ffo(i, n) forex (i, n, 0)
#define mid ((l+r)>>1)
bool cmin(ll &a, ll b) { if (b < a) { a=b; return 1; } return 0; }
bool cmax(ll &a, ll b) { if (b > a) { a=b; return 1; } return 0; }
const int N = 105;
ll myquery (vll a, vll b) {
ll n = a.size(), m = b.size();
int A[n], B[m];
fo (i, a.size()) A[i] = a[i];
fo (i, b.size()) B[i] = b[i];
return query(n, m, A, B);
}
vll graph[N];
ll vis[N];
void dfs (ll u, ll p, ll d, vector<vll> &pth) {
pth[d].pb(u);
vis[u] = 1;
for (ll v: graph[u]) {
if (v == p) continue;
dfs(v, u, d^1, pth);
}
}
ll binaria (vll A, vll B) {
ll l = 0, r = A.size() - 1;
while (l < r) {
ll m = (l+r)/2;
vll okpth;
fo (i, m+1) okpth.pb(A[i]);
if (myquery(okpth, B)) r = m;
else l = m+1;
}
return A[l];
}
array<ll, 2> find (vll pth) {
vll c(7, 0ll);
vll foundA, foundB;
fo (bt, 7) {
if ((1ll<<bt) >= pth.size()) break;
vll A, B;
fo (i, pth.size()) {
if (i&(1ll<<bt)) A.pb(pth[i]);
else B.pb(pth[i]);
}
if (myquery(A, B)) {
c[bt] = 1;
foundA = A;
foundB = B;
} else {
c[bt] = 0;
}
}
if (foundA.size() != 0) {
ll a = binaria(foundA, foundB);
ll b = a;
fo (bt, 7) if (c[bt]) b ^= 1ll<<bt;
return {a, b};
}
return {-1, -1};
}
void run (int n) {
fo (i, n+1) {
graph[i].clear();
}
fo (_, n-1) {
fo (i, n+1) vis[i] = 0;
vector<vll> pth(2);
fore (a, 1, n+1) {
if (vis[a]) continue;
dfs(a, -1, 0, pth);
}
if (myquery(pth[0], pth[1])) {
ll a = binaria(pth[0], pth[1]);
ll b = binaria(pth[1], pth[0]);
setRoad(a, b);
graph[a].pb(b);
graph[b].pb(a);
continue;
}
auto ans = find(pth[0]);
if (ans != array<ll, 2>{-1, -1}) {
graph[ans[0]].pb(ans[1]);
graph[ans[1]].pb(ans[0]);
setRoad(ans[0], ans[1]);
continue;
}
ans = find(pth[1]);
graph[ans[0]].pb(ans[1]);
graph[ans[1]].pb(ans[0]);
setRoad(ans[0], ans[1]);
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |