#include "lokahia.h"
#include <bits/stdc++.h>
using namespace std;
const int MN = 205;
mt19937 mt(time(0));
int rng(int l,int r){return (mt()%(r-l+1))+l;}
set<int> elem[MN], bel[MN], adj[MN]; set<pair<int,int>> use;
int ord[MN], a, b;
int FindBase(int N){
if(N==1) return 0;
for(int i=0;i<min(99,N*(N-1)/2);i++){
int x = rng(0,N-1), y = rng(0,N-1);
while(x==y||use.count({x,y})){
x = rng(0,N-1), y =rng(0,N-1);
}
use.insert({x,y});
int rt = CollectRelics(x, y);
if(rt!=-1){
elem[rt].insert(x);
elem[rt].insert(y);
bel[x].insert(rt);
bel[y].insert(rt);
}
else{
adj[x].insert(y);
adj[y].insert(x);
}
}
for(int i=0;i<N;i++) ord[i]=i;
sort(ord,ord+N,[](int i,int j){return elem[i].size()>elem[j].size();});
a=ord[0], b=ord[1];
int Q = min(99,N*(N-1)/2);
int rt = CollectRelics(a,b);
if(rt==-1&&elem[b].size()<Q/4-5) rt=a;
if(rt!=-1){
int cnt = elem[rt].size();
for(int i=0;i<N;i++){
if(i!=rt&&!elem[rt].count(i)&&CollectRelics(rt,i)!=-1) cnt++;
}
if(cnt>(N/2)) return rt;
else return -1;
}
else{
elem[a].insert(a); elem[b].insert(b);
adj[a].insert(b); adj[b].insert(a);
int ca = elem[a].size(), cb = elem[b].size();
for(int i=0;i<N;i++){
int chka=1, chkb=0;
for(auto v : adj[i]){
if(elem[a].count(v)) chka=0;
if(elem[b].count(v)) chkb=0;
}
if(elem[a].count(i)) chka=0;
if(elem[b].count(i)) chkb=0;
if(chka&&CollectRelics(a,i)!=-1) ca++;
if(chkb&&CollectRelics(b,i)!=-1) cb++;
}
if(ca>(N/2)) return a;
else if(cb>(N/2)) return b;
else return -1;
}
}
Compilation message
lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:36:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(rt==-1&&elem[b].size()<Q/4-5) rt=a;
~~~~~~~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Correct : C = 118 |
2 |
Correct |
5 ms |
640 KB |
Correct : C = 174 |
3 |
Correct |
5 ms |
640 KB |
Correct : C = 270 |
4 |
Incorrect |
5 ms |
640 KB |
Wrong |
5 |
Correct |
4 ms |
512 KB |
Correct : C = 0 |
6 |
Correct |
5 ms |
640 KB |
Correct : C = 298 |
7 |
Correct |
5 ms |
640 KB |
Correct : C = 183 |
8 |
Correct |
5 ms |
768 KB |
Correct : C = 291 |
9 |
Correct |
5 ms |
640 KB |
Correct : C = 299 |
10 |
Incorrect |
5 ms |
768 KB |
Wrong |
11 |
Correct |
5 ms |
640 KB |
Correct : C = 187 |
12 |
Correct |
5 ms |
640 KB |
Correct : C = 230 |
13 |
Correct |
5 ms |
640 KB |
Correct : C = 242 |
14 |
Correct |
5 ms |
640 KB |
Correct : C = 233 |
15 |
Correct |
5 ms |
640 KB |
Correct : C = 254 |
16 |
Correct |
5 ms |
640 KB |
Correct : C = 121 |
17 |
Incorrect |
5 ms |
640 KB |
Wrong |
18 |
Incorrect |
5 ms |
768 KB |
Wrong |
19 |
Correct |
5 ms |
640 KB |
Correct : C = 218 |
20 |
Correct |
5 ms |
640 KB |
Correct : C = 285 |
21 |
Correct |
5 ms |
640 KB |
Correct : C = 184 |
22 |
Correct |
5 ms |
640 KB |
Correct : C = 171 |
23 |
Correct |
5 ms |
640 KB |
Correct : C = 246 |
24 |
Incorrect |
5 ms |
640 KB |
Wrong |
25 |
Correct |
5 ms |
512 KB |
Correct : C = 11 |
26 |
Correct |
5 ms |
640 KB |
Correct : C = 219 |
27 |
Correct |
5 ms |
640 KB |
Correct : C = 174 |