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 "icc.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
const int maxn = 105;
int n;
int ok[maxn][maxn];
int par[maxn];
}
int find(int u) {
return par[u] == u ? u : par[u] = find(par[u]);
}
void unite(int u, int v) {
u = find(u), v = find(v);
if(u == v) return;
if(rand() % 2) swap(u, v);
par[u] = v;
}
void addedge(int u, int v) {
ok[u][v] = ok[v][u] = 1;
setRoad(u, v);
unite(u, v);
}
int ask(vector<int> x, vector<int> y) {
int tmp = query((int)x.size(), (int)y.size(), x.data(), y.data());
// cout << "[Query]" << endl;
// cout << "a = {"; for(int i : x) cout << i << ","; cout << "}" << endl;
// cout << "b = {"; for(int i : y) cout << i << ","; cout << "}" << endl;
// cout << "tmp = " << tmp << endl;
return tmp;
}
int chex(int u) {
vector<int> a(1, u), b;
for(int i = 1; i <= n; i++) {
if(i != u and !ok[u][i]) {
b.push_back(i);
}
}
if(b.empty()) return 0;
return ask(a, b);
}
int find_another(int u) {
vector<int> vec(n);
iota(vec.begin(), vec.end(), 1);
random_shuffle(vec.begin(), vec.end(), [](int i){return rand() % i;});
for(int i : vec) {
if(i != u and !ok[u][i] /*and find(i) != find(u)*/) {
if(ask(vector<int>(1, u), vector<int>(1, i))) {
return i;
}
}
} assert(false);
}
void run(int N) {
srand(time(0));
memset(ok, 0, sizeof ok);
n = N;
int rnd = n - 1;
while(rnd--) {
int u = 0;
vector<int> vec(n);
iota(vec.begin(), vec.end(), 1);
random_shuffle(vec.begin(), vec.end(), [](int i){return rand() % i;});
for(int i : vec)
if(chex(i)) { u = i; break; }
int v = find_another(u);
addedge(u, v);
}
}
# | 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... |