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;
typedef vector<int> vi;
vi p, rk, sz;
void init(int n){
for(int i = 0; i < n; i++){
p.push_back(i);
rk.push_back(0);
sz.push_back(1);
}
}
int findset(int x){
return p[x] == x ? x : p[x] = findset(p[x]);
}
bool sameset(int i, int j){
return findset(i) == findset(j);
}
void unionset(int i, int j){
int x = findset(i), y = findset(j);
if (x == y) return;
if (rk[x] < rk[y]){
p[x] = y;
sz[y] += sz[x];
}
else{
p[y] = x;
sz[x] += sz[y];
if (rk[x] == rk[y]) rk[x]++;
}
}
void run(int n) {
int cur = 0;
init(n);
vector<int> random;
for (int i = 1; i <= n; i++) random.push_back(i);
random_shuffle(random.begin(),random.end());
int a[1], b[1];
while (cur < n){
bool done = false;
for (int i = 0; i < n; i++){
for (int j = i+1; j < n; j++){
//printf("%d %d\n",i,j);
a[0] = random[i], b[0] = random[j];
//printf("%d ",b[0]);
if (sameset(a[0]-1,b[0]-1)) continue;
if (query(1,1,a,b) == 1){
setRoad(a[0],b[0]);
unionset(a[0]-1,b[0]-1);
done = true;
cur++;
break;
}
}
//printf("done with %d\n",a[0]);
if (done) break;
}
}
}
# | 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... |