/* Bismillahir Rahmanir Rahim */
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
const int N = 105;
int n, par[N], mat[N][N];
set<int>comp;
vector<int>nudes[N];
int Find(int at){
return par[at] == at ? at : par[at] = Find(par[at]);
}
void Union(int a, int b){
int x = Find(a);
int y = Find(b);
/* cout << "ADD " << a << ' ' << b << endl; */
for(auto u : nudes[y]){
nudes[x].push_back(u);
}
par[y] = x;
comp.erase(y);
}
/* void setRoad(int a, int b){ */
/* if(a) Union(a, b); */
/* int x, y; */
/* cin >> x >> y; */
/* mat[x][y] = 1; */
/* mat[y][x] = 1; */
/* } */
/* int query(int sa, int sb, int a[], int b[]){ */
/* for(int i=0;i<sa;i++){ */
/* for(int j=0;j<sb;j++){ */
/* if(mat[a[i]][b[j]]) return true; */
/* } */
/* } */
/* return false; */
/* } */
int fuk[N], tt;
int get(int sa, int sb, int a[], int b[]){
int lo = 0, hi = sb - 1;
while(lo < hi){
int mid = (lo + hi) / 2; tt = 0;
for(int i=lo;i<=mid;i++) fuk[tt] = b[i], ++tt;
if(query(sa, tt, a, fuk)) hi = mid;
else lo = mid + 1;
}
return b[lo];
}
int aa[N], bb[N];
int sa, sb;
void run(int _n){
srand(time(NULL));
n = _n;
comp.clear();
for(int i=1;i<=n;i++){
par[i] = i;
comp.insert(i);
nudes[i].push_back(i);
}
int road = n - 1;
while(road--){
while(1){
sa = 0, sb = 0;
vector<int>nd;
for(auto u : comp) nd.push_back(u);
random_shuffle(nd.begin(), nd.end());
int mid = nd.size() / 2;
for(int i=0;i<mid;i++){
for(auto u : nudes[nd[i]]){
aa[sa] = u;
++sa;
}
}
for(int i=mid;i<nd.size();i++){
for(auto u : nudes[nd[i]]){
bb[sb] = u;
++sb;
}
}
/* cout << "-------\n"; */
/* cout << nd.size() << ' ' << comp.size() << endl; */
/* for(auto u : comp) cout << u << ' '; cout << endl; */
/* for(int i=0;i<sa;i++) cout << aa[i] << ' '; cout << endl; */
/* for(int i=0;i<sb;i++) cout << bb[i] << ' '; cout << endl; */
if(query(sa, sb, aa, bb)){
int x = get(sa, sb, aa, bb);
int y = get(sb, sa, bb, aa);
Union(x, y);
setRoad(x, y);
break;
}
}
}
}
/* int main(){ */
/* int ff, x, y; */
/* scanf("%d", &ff); */
/* setRoad(0, 0); */
/* run(ff); */
/* return 0; */
/* } */
Compilation message
icc.cpp: In function 'void run(int)':
icc.cpp:85:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=mid;i<nd.size();i++){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2132 KB |
Ok! 99 queries used. |
2 |
Correct |
6 ms |
2136 KB |
Ok! 108 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
2136 KB |
Ok! 542 queries used. |
2 |
Correct |
63 ms |
2140 KB |
Ok! 845 queries used. |
3 |
Correct |
49 ms |
2140 KB |
Ok! 769 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
2264 KB |
Ok! 1516 queries used. |
2 |
Correct |
179 ms |
2272 KB |
Ok! 2110 queries used. |
3 |
Correct |
143 ms |
2264 KB |
Ok! 1720 queries used. |
4 |
Correct |
143 ms |
2264 KB |
Ok! 1690 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
2272 KB |
Ok! 1560 queries used. |
2 |
Correct |
133 ms |
2264 KB |
Ok! 1610 queries used. |
3 |
Correct |
159 ms |
2264 KB |
Ok! 1860 queries used. |
4 |
Correct |
133 ms |
2264 KB |
Ok! 1577 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
156 ms |
2264 KB |
Too many queries! 1883 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
156 ms |
2264 KB |
Too many queries! 1867 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |