#include "lokahia.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
ll chk[210][210];
ll cou[210];
ll grp[210];
ll pa[210], ra[210];
ll cou2[210];
ll ffind(ll here)
{
if(here == pa[here])
return pa[here];
return pa[here] = ffind(pa[here]);
}
void uunion(ll X, ll Y)
{
X = ffind(X);
Y = ffind(Y);
if(X == Y)
return;
if(ra[X] < ra[Y])
pa[X] = Y;
else if(ra[Y] < ra[X])
pa[Y] = X;
else
{
pa[X] = Y;
ra[Y]++;
}
}
ll FindBase(ll N)
{
if(N <= 3)
return 1;
srand(time(NULL));
if(N <= 17)
{
for(ll i = 0 ; i < N ; i++)
{
for(ll j = i + 1 ; j < N ; j++)
{
ll gap = CollectRelics(i, j);
if(gap != -1)
{
grp[i] = gap;
grp[j] = gap;
}
}
}
for(ll i = 0 ; i < N ; i++)
cou[grp[i]]++;
ll maxx = 0, ans = 0;
for(ll i = 0 ; i < N ; i++)
{
if(maxx < cou[i])
{
maxx = cou[i];
ans = i;
}
}
if(maxx * 2 >= N)
return ans;
return -1;
}
for(ll i = 0 ; i < N ; i++)
pa[i] = i, ra[i] = 0;
for(ll i = 0 ; i < 300 ; i++)
{
ll num1 = rand() % N, num2 = rand() % N;
ll coco = 0;
while(chk[num1][num2] || num1 == num2 || ffind(num1) == ffind(num2))
{
num1 = rand() % N;
num2 = rand() % N;
coco++;
if(coco >= 100000)
break;
}
if(coco >= 100000)
continue;
ll gap = CollectRelics(num1, num2);
chk[num1][num2] = chk[num2][num1] = 1;
if(gap != -1)
{
cou[gap]++;
grp[num1] = gap;
grp[num2] = gap;
grp[gap] = gap;
uunion(num1, num2);
uunion(gap, num2);
}
}
for(ll i = 0 ; i < N ; i++)
cou2[grp[i]]++;
for(ll i = 0 ; i < N ; i++)
{
if(cou2[i] >= N / 2)
return i;
}
ll maxx = 0, sum = 0, ans = 0;
for(ll i = 0 ; i < N ; i++)
{
if(cou[i] > maxx)
{
maxx = cou[i];
ans = i;
}
sum += cou[i];
}
if(sum - maxx * 2 <= 10)
return ans;
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Wrong |
2 |
Correct |
1 ms |
724 KB |
Correct : C = 300 |
3 |
Correct |
271 ms |
724 KB |
Correct : C = 151 |
4 |
Correct |
294 ms |
768 KB |
Correct : C = 144 |
5 |
Incorrect |
1 ms |
792 KB |
Wrong |
6 |
Incorrect |
1 ms |
724 KB |
Wrong |
7 |
Incorrect |
1 ms |
596 KB |
Wrong |
8 |
Incorrect |
1 ms |
724 KB |
Wrong |
9 |
Incorrect |
1 ms |
724 KB |
Wrong |
10 |
Correct |
1 ms |
596 KB |
Correct : C = 300 |
11 |
Correct |
1 ms |
724 KB |
Correct : C = 300 |
12 |
Correct |
1 ms |
724 KB |
Correct : C = 300 |
13 |
Incorrect |
1 ms |
724 KB |
Wrong |
14 |
Correct |
1 ms |
724 KB |
Correct : C = 300 |
15 |
Incorrect |
1 ms |
724 KB |
Wrong |
16 |
Correct |
389 ms |
640 KB |
Correct : C = 97 |
17 |
Incorrect |
1 ms |
596 KB |
Wrong |
18 |
Incorrect |
1 ms |
596 KB |
Wrong |
19 |
Correct |
0 ms |
468 KB |
Correct : C = 10 |
20 |
Incorrect |
0 ms |
468 KB |
Wrong |
21 |
Incorrect |
1 ms |
724 KB |
Wrong |
22 |
Incorrect |
1 ms |
596 KB |
Wrong |
23 |
Correct |
1 ms |
596 KB |
Correct : C = 300 |
24 |
Incorrect |
1 ms |
724 KB |
Wrong |
25 |
Correct |
1 ms |
724 KB |
Correct : C = 300 |
26 |
Correct |
400 ms |
652 KB |
Correct : C = 89 |
27 |
Correct |
1 ms |
596 KB |
Correct : C = 300 |