#include "icc.h"
#define N 105
#include <bits/stdc++.h>
using namespace std;
set<int> grafo[N];
int pai[N], peso[N];
int Find(int x)
{
if(x == pai[x]) return x;
return pai[x] = Find(pai[x]);
}
void join(int a, int b)
{
a = Find(a), b = Find(b);
if(a == b) return;
if(peso[a] > peso[b]) pai[b] = a;
else if(peso[a] < peso[b]) pai[a] = b;
else pai[a] = b, peso[b] ++;
}
void run(int n)
{
for(int i = 1; i <= n; i++)
{
pai[i] = i;
}
for(int i = 1; i < n; i++)
{
vector<int> ok;
vector<int> valores, aux;
for(int a = 1; a <= n; a++) valores.push_back(a);
random_shuffle(valores.begin(), valores.end());
for(auto a: valores)
{
int esq[N], dir[N], id = 0;
if(ok.size() >= 1) break;
esq[0] = a;
for(int b = 1; b <= n; b++)
{
if(Find(a) != Find(b))
{
dir[id] = b;
id ++;
}
}
if(query(1, id, esq, dir) > 0)
{
ok.push_back(a);
break;
}
}
for(int a = 1; a <= n; a++)
{
if(Find(a) != Find(ok[0]))
{
aux.push_back(a);
// cout<<"COLOCA "<<a<<'\n';
}
}
int ini = 0, fim = aux.size() - 1, mid, best;
while(fim >= ini)
{
mid = (ini + fim)/2;
int esq[N], dir[N];
esq[0] = ok[0];
for(int i = 0; i <= mid; i++) dir[i] = aux[i];
//cout<<mid<<" "<<query(1, mid + 1, esq, dir)<<"\n";
if(query(1, mid + 1, esq, dir))
{
best = mid;
fim = mid - 1;
}
else ini = mid + 1;
}
// cout<<"ROAD "<<ok[0]<<" "<<aux[best]<<"\n";
join(ok[0], aux[best]);
setRoad(ok[0], aux[best]);
}
}
Compilation message
icc.cpp: In function 'void run(int)':
icc.cpp:109:33: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
join(ok[0], aux[best]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
632 KB |
Ok! 227 queries used. |
2 |
Correct |
17 ms |
632 KB |
Ok! 213 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
632 KB |
Ok! 2358 queries used. |
2 |
Incorrect |
191 ms |
784 KB |
Too many queries! 2553 out of 2500 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
498 ms |
784 KB |
Number of queries more than 4500 out of 2250 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
384 ms |
784 KB |
Number of queries more than 4000 out of 2000 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
347 ms |
784 KB |
Number of queries more than 3550 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
345 ms |
784 KB |
Number of queries more than 3250 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |