#include "lokahia.h"
#include <stdio.h>
int root[205]; // who is root?
int select[205]; // able to get mana?
int getRoot(int n) {
int r = root[n];
if(r == -1) return n;
findRoot(r, n);
root[n] = getRoot(r);
return root[n];
}
int findRoot(int r, int leaf) {
if(r == leaf) return select[r];
int temp = root[leaf];
select[r] += select[leaf];
root[leaf] = r;
select[leaf] = 0;
return temp == -1 ? select[r]: findRoot(r, temp);
}
int FindBase(int N){
int target = N / 2;
int boss[205];
int bossNum = 0;
for(int i =0; i < N; i++) {
root[i] = -1;
select[i] = 1;
boss[i] = 0;
}
for(int i =0; i< N;) {
int s = 1;
boss[bossNum++] = i;
for(int j =i+1; j < N; j++) {
int r = CollectRelics(i, j);
if( r == -1) {
s--;
if(s == 0) {
i = j+1;
if(i == N) return -1;
break;
}
continue;
}
int num = findRoot(r, i);
num = findRoot(r,j);
if(num > target) return r;
s++;
}
}
int c = boss[bossNum-1];
for(int i =0; i < bossNum-1; i++) {
int a = boss[i];
int r = CollectRelics(c, a);
if(r == -1) {
int b = boss[i+1];
for(int j = a+1; j < b; j++) {
r = CollectRelics(c, j);
if(r == -1) continue;
int num = findRoot(r, c);
num = findRoot(r, j);
if(num > target) return r;
}
continue;
}
int num = findRoot(r, c);
num = findRoot(r, a);
if(num > target) return r;
}
if(root[c] == -1 && select[c] > target ) return c;
else if(root[c] != -1 && select[getRoot(c)] > target) return root[c];
return -1;
}
Compilation message
lokahia.cpp: In function 'int getRoot(int)':
lokahia.cpp:10:2: error: 'findRoot' was not declared in this scope
10 | findRoot(r, n);
| ^~~~~~~~