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 "meetings.h"
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;
const int MAXN = 2010;
// struct DSU {
// int p[MAXN];
// void init() {
// memset(p, -1, sizeof(p));
// }
// int find(int n) {
// if(p[n] < 0) return n;
// return p[n] = find(p[n]);
// }
// void uni(int a, int b) {
// a = find(a); b = find(b);
// if(a != b) p[b] = a;
// }
// } dsu;
mt19937_64 rng(48763);
vector<pii> edges;
int m_qry(int a, int b, int c) {
if(a == b) return a;
if(a == c) return a;
if(b == c) return b;
return Query(a, b, c);
}
void solve(vector<int> &ids) {
if(sz(ids) == 1) return;
if(sz(ids) == 2) {
edges.eb(ids[0], ids[1]);
// for(auto &i:ids) cout << i << " ";
// cout << " - " << ids[0] << " " << ids[1] << "\n" << flush;
return;
}
int rt = rng() % sz(ids);
int p1 = rng() % sz(ids);
while(p1 == rt) p1 = rng() % sz(ids);
rt = ids[rt]; p1 = ids[p1];
int p2 = p1;
vector<int> a(1, p1), b(1, rt);
for(auto &i:ids) if(i != rt && i != p1) {
// cout << rt << " " << p2 << " " << i << "\n" << flush;
auto res = m_qry(rt, p2, i);
if(res != rt) {
a.eb(i);
p2 = res;
} else {
b.eb(i);
}
}
// for(auto &i:ids) cout << i << " ";
// cout << " - " << rt << " " << p2 << "\n" << flush;
edges.eb(rt, p2);
solve(a);
solve(b);
}
void Solve(int32_t n) {
edges.clear();
vector<int> ids(n);
For(i, 0, n - 1) ids[i] = i;
solve(ids);
for(auto &p:edges) {
if(p.F > p.S) swap(p.F, p.S);
Bridge(p.F, p.S);
}
}
// int x = Query(0, 1, 2);
// for (int u = 0; u < N - 1; ++u) {
// Bridge(u, u + 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... |