#include <bits/stdc++.h>
#include "icc.h"
#define DIM 200
using namespace std;
vector <int> L[DIM],comp[DIM],w;
int n,i,x,y,k,k2;
int v[DIM],t[DIM],aux[DIM],a[DIM],b[DIM];
/*int query (int n, int m, int a[], int b[]){
int ans;
cout<<n<<" ";
for (int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
cout<<m<<" ";
for (int i=0;i<m;i++)
cout<<b[i]<<" ";
cout<<endl;
cin>>ans;
return ans;
}
void setRoad (int x, int y){
cout<<x<<" "<<y<<endl;
}
*/
int get_rad (int x){
while (t[x] > 0)
x = t[x];
return x;
}
void _union (int x, int y){
int radx = get_rad (x), rady = get_rad (y);
if (radx != rady){
if (t[radx] < t[rady]){
t[radx] += t[rady];
t[rady] = radx;
} else {
t[rady] += t[radx];
t[radx] = rady;
}
}
}
void solve2 (int n, int m, int a[], int b[]){
int st = 0, dr = n-1;
while (st <= dr){
int mid = (st+dr)>>1;
int el = 0;
aux[el++] = a[mid];
if (query(el,m,aux,b)){
x = a[mid];
break;
}
el = 0;
for (int i=st;i<=mid;i++)
aux[el++] = a[i];
if (query(el,m,aux,b)) /// clar se afla in stanga
dr = mid-1;
else st = mid+1;
}
//n = 1;
//a[0] = x;
st = 0, dr = m-1;
while (st <= dr){
int mid = (st+dr)>>1;
int el = 0;
aux[el++] = b[mid];
if (query(n,el,a,aux)){
y = b[mid];
break;
}
el = 0;
for (int i=st;i<=mid;i++)
aux[el++] = b[i];
if (query(n,el,a,aux))
dr = mid-1;
else st = mid+1;
}
}
void solve (){
/// impart componentele conexe in doua multimi
for (int bit=0;bit<7;bit++){
k = 0, k2 = 0;
for (int i=1;i<=n;i++){
int val = get_rad(i);
if (val&(1<<bit))
a[k++] = i;
else b[k2++] = i;
}
if (!k || !k2)
continue;
if (query(k,k2,a,b)){ /// am gasit cele doua multimi
solve2 (k,k2,a,b);
break;
}
}
_union (x,y);
}
void run (int n){
memset (t,-1,sizeof t);
for (int i=1;i<n;i++){
solve();
setRoad(x,y);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
256 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |