#include "lokahia.h"
#include <stdlib.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
int p[706];
int query[706][3];
int find(int a){
if(p[a] < 0) return a;
return p[a] = find(p[a]);
}
int uni(int a, int b){
a = find(a);
b = find(b);
if(a==b) return 0;
p[a] += p[b];
p[b] = a;
return -p[a];
}
int mysize(int a){
if(p[a] < 0) return -p[a];
return mysize(p[a]);
}
int FindBase(int N){
srand(234316);
int GROUP_IDX = N+1;
if(N==1) return 0;
for(int i = 0; i < 700; i++){
p[i] = -1;
}
int GUESS_IDX = 0;
while(GUESS_IDX < 400){
int a = 0, b = 0;
while(find(a) == find(b)){
a = rand()%N;
b = rand()%N;
//printf("%d %d %d %d\n",a,b,find(a),find(b));
}
int ret = CollectRelics(a,b);
//printf("%d %d %d\n",a,b,ret);
query[GUESS_IDX][0]=a;
query[GUESS_IDX][1]=b;
query[GUESS_IDX][2]=ret;
if(ret != -1){
uni(a, b);
uni(a,ret);
int sz = mysize(a);
if(sz > N/2){
int ret = -1;
for(int i = 0; i < GUESS_IDX; i++){
if(find(query[GUESS_IDX][0]) != find(a) or find(query[GUESS_IDX][1]) != find(a)) continue;
ret = max(ret, query[GUESS_IDX][1]);
}
return ret;
}
}
GUESS_IDX++;
}
int mxidx = 0;
for(int i = 0; i < N; i++){
if(-p[i] > -p[mxidx]) mxidx = i;
}
int ret = -1;
for(int i = 0; i < GUESS_IDX; i++){
if(find(query[GUESS_IDX][0]) != find(mxidx) or find(query[GUESS_IDX][1]) != find(mxidx)) continue;
ret = max(ret, query[GUESS_IDX][1]);
}
int cnt = 1;
for(int i = 0; i < N; i++){
if(i==ret) continue;
if(CollectRelics(i,ret) != -1) cnt++;
}
if(cnt > N/2) return ret;
else return -1;
}
Compilation message
lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:29:7: warning: unused variable 'GROUP_IDX' [-Wunused-variable]
int GROUP_IDX = N+1;
^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
7 ms |
640 KB |
Partially correct : C = 598 |
2 |
Incorrect |
6 ms |
512 KB |
Wrong |
3 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 599 |
4 |
Incorrect |
6 ms |
640 KB |
Wrong |
5 |
Incorrect |
6 ms |
384 KB |
Wrong |
6 |
Incorrect |
6 ms |
640 KB |
Wrong |
7 |
Incorrect |
6 ms |
640 KB |
Wrong |
8 |
Incorrect |
6 ms |
512 KB |
Wrong |
9 |
Partially correct |
5 ms |
512 KB |
Partially correct : C = 518 |
10 |
Incorrect |
6 ms |
640 KB |
Wrong |
11 |
Correct |
6 ms |
512 KB |
Correct : C = 217 |
12 |
Incorrect |
6 ms |
640 KB |
Wrong |
13 |
Incorrect |
6 ms |
512 KB |
Wrong |
14 |
Incorrect |
6 ms |
512 KB |
Wrong |
15 |
Incorrect |
6 ms |
640 KB |
Wrong |
16 |
Partially correct |
6 ms |
640 KB |
Partially correct : C = 599 |
17 |
Incorrect |
6 ms |
512 KB |
Wrong |
18 |
Incorrect |
7 ms |
640 KB |
Wrong |
19 |
Incorrect |
6 ms |
512 KB |
Wrong |
20 |
Incorrect |
6 ms |
512 KB |
Wrong |
21 |
Incorrect |
6 ms |
512 KB |
Wrong |
22 |
Incorrect |
6 ms |
640 KB |
Wrong |
23 |
Partially correct |
6 ms |
512 KB |
Partially correct : C = 519 |
24 |
Incorrect |
5 ms |
512 KB |
Wrong |
25 |
Incorrect |
7 ms |
640 KB |
Wrong |
26 |
Correct |
5 ms |
512 KB |
Correct : C = 0 |
27 |
Incorrect |
6 ms |
640 KB |
Wrong |