# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
249021 | SomeoneUnknown | 로카히아 유적 (FXCUP4_lokahia) | C++17 | 1 ms | 640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "lokahia.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> par;
vector<bool> matched;
int getpar(int x){
//printf("getpar %d\n", x);
if(par[x] != x){
par[x] = getpar(par[x]);
}
return par[x];
}
int FindBase(int N){
//int par[N];
int disjointtotal = 0;
for(int i = 0; i < N; ++i){
par.push_back(i);
matched.push_back(false);
}
int frst;
while(true){
frst = -1;
bool fin = true;
for(int i = 0; i < N; ++i){
if(matched[i]) continue;
if(frst == -1){
frst = i;
continue;
}
if(getpar(frst) != getpar(i)){
int res = CollectRelics(getpar(frst), getpar(i));
if(res == -1){
++disjointtotal;
if(disjointtotal * 2 >= N) return -1;
matched[i] = matched[frst] = true;
}else{
res = getpar(res);
par[getpar(frst)] = res;
par[getpar(i)] = res;
}
fin = false;
break;
}
}
if(fin) break;
}
int llone = frst; //yes, this is copypasted.
for(int i = 0; i < N; ++i){
if(i == llone || par[i] != i) continue;
int res = CollectRelics(i, llone);
if(res == -1) continue;
res = getpar(res);
par[llone] = res;
par[i] = res;
llone = res;
}
int llonesize = 0;
for(int i = 0; i < N; ++i){
if(getpar(i) == llone) llonesize++;
}
if(llonesize * 2 > N) return llone;
//CollectRelics()
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |