#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
const int maxn = 110;
int pai[maxn], peso[maxn];
int A[maxn], B[maxn];
vector<int> comp[maxn];
void init(int n)
{
for (int i = 1; i <= n; i++)
{
pai[i] = i, peso[i] = 1;
comp[i].push_back(i);
}
}
int Find(int x)
{
if (pai[x] == x) return x;
return pai[x] = Find(pai[x]);
}
void Join(int x, int y)
{
x = Find(x), y = Find(y);
if (x == y) return;
if (x > y) swap(x, y);
pai[y] = x, peso[x] += peso[y];
for (auto v: comp[y])
comp[x].push_back(v);
}
void run(int n)
{
init(n);
for (int e = 1; e < n; e++)
{
int qwerty = 0;
for (int i = 1; i <= n; i++)
{
if (Find(i) == i)
{
for (int j = 0; j < 7; j++)
if (i&(1<<j))
qwerty = max(qwerty,j);
}
}
for (int b = 0; b <= qwerty; b++)
{
int sz_a = -1, sz_b = -1;
for (int i = 1; i <= n; i++)
{
if (Find(i) == i)
{
if (i&(1<<b))
{
for (auto v: comp[i])
A[++sz_a] = v;
}
else
{
for (auto v: comp[i])
B[++sz_b] = v;
}
}
}
if (b < 6 && !query(sz_a+1, sz_b+1, A, B)) continue;
int ini = 0, fim = sz_a, ans = -1;
while (ini <= fim)
{
int mid = (ini+fim)>>1;
if (query(mid+1, sz_b+1, A, B)) ans = mid, fim = mid-1;
else ini = mid+1;
}
ini = 0, fim = sz_b;
int ans2 = -1;
while (ini <= fim)
{
int mid = (ini+fim)>>1;
if (query(ans+1, mid+1, A, B)) ans2 = mid, fim = mid-1;
else ini = mid+1;
}
setRoad(A[ans], B[ans2]);
Join(A[ans], B[ans2]);
break;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
504 KB |
Ok! 105 queries used. |
2 |
Correct |
9 ms |
504 KB |
Ok! 107 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
632 KB |
Ok! 540 queries used. |
2 |
Correct |
53 ms |
504 KB |
Ok! 685 queries used. |
3 |
Correct |
53 ms |
632 KB |
Ok! 682 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
632 KB |
Ok! 1393 queries used. |
2 |
Correct |
172 ms |
504 KB |
Ok! 1649 queries used. |
3 |
Correct |
136 ms |
600 KB |
Ok! 1370 queries used. |
4 |
Correct |
166 ms |
504 KB |
Ok! 1546 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
504 KB |
Ok! 1518 queries used. |
2 |
Correct |
169 ms |
504 KB |
Ok! 1556 queries used. |
3 |
Correct |
175 ms |
504 KB |
Ok! 1657 queries used. |
4 |
Correct |
137 ms |
632 KB |
Ok! 1364 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
632 KB |
Ok! 1618 queries used. |
2 |
Correct |
176 ms |
596 KB |
Ok! 1656 queries used. |
3 |
Correct |
173 ms |
504 KB |
Ok! 1649 queries used. |
4 |
Correct |
175 ms |
560 KB |
Ok! 1638 queries used. |
5 |
Correct |
150 ms |
504 KB |
Ok! 1456 queries used. |
6 |
Correct |
169 ms |
556 KB |
Ok! 1597 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
172 ms |
504 KB |
Too many queries! 1637 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |