#include "lokahia.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> thing[205];
int qLim = 600;
int p[205];
bool vis[205];
int root(int a){
return p[a]==a?a:p[a]=root(p[a]);
}
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
int sz[205];
int queryCount = 0;
int query(int a, int b){
if (queryCount>=qLim){
return -2;
}
if (a==b) return a;
int res = CollectRelics(a,b);
queryCount++;
if (res!=-1){
thing[res].push_back(a);
thing[res].push_back(b);
//printf("add edge %d %d, %d %d\n",res,a,res,b);
}
return res;
}
int dfs(int node){
vis[node] = true;
int res = 1;
for (auto x : thing[node]){
if (!vis[x]){
res += dfs(x);
}
}
return res;
}
int FindBase(int N){
for (int x = 0; x<N; x++){
pq.push({1,x});
p[x] = x;
}
int mn = -1;
while (!pq.empty()){
if (pq.size()<3){
if (pq.size()==1) {mn = pq.top().second;pq.pop();}
else{
auto a = pq.top();
pq.pop();
auto b = pq.top();
pq.pop();
int r = query(a.second,b.second);
if (r==-2) return -1;
if (r==-1){
mn = sz[a.second]>sz[b.second]?a.second:b.second;
}
}
continue;
}
auto a = pq.top();
pq.pop();
auto b = pq.top();
pq.pop();
auto c = pq.top();
pq.pop();
int res = query(a.second,b.second);
if (res==-2) return -1;
if (res==-1){
int r2 = query(a.second,c.second);
if (r2==-2) return -1;
if (r2==-1) {
int r3 = query(b.second,c.second);
if (r3==-2) return -1;
if (r3!=-1){
if (root(b.second)!=root(r3)){
p[root(b.second)] = r3;
sz[root(r3)] += sz[root(b.second)];
}
if (root(c.second)!=root(r3)){
p[root(c.second)] = r3;
sz[root(r3)] += sz[root(c.second)];
}
pq.push({sz[root(r3)],r3});
}
}
else{
if (root(a.second)!=root(r2)){
p[root(a.second)] = r2;
sz[root(r2)] += sz[root(a.second)];
}
if (root(c.second)!=root(r2)){
p[root(c.second)] = r2;
sz[root(r2)] += sz[root(c.second)];
}
pq.push({sz[root(r2)],r2});
}
}
else{
if (root(b.second)!=root(res)){
p[root(b.second)] = res;
sz[root(res)] += sz[root(b.second)];
}
if (root(a.second)!=root(res)){
p[root(a.second)] = res;
sz[root(res)] += sz[root(a.second)];
}
pq.push({sz[root(res)],res});
}
}
for (int x = 0; x<N; x++){
if (root(x)!=root(mn)){
query(x,root(mn));
}
}
for (int x = 0; x<N; x++){
if (dfs(x)>N/2){
return x;
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
640 KB |
Wrong |
2 |
Correct |
5 ms |
640 KB |
Correct : C = 199 |
3 |
Partially correct |
6 ms |
640 KB |
Partially correct : C = 395 |
4 |
Incorrect |
5 ms |
512 KB |
Wrong |
5 |
Correct |
5 ms |
640 KB |
Correct : C = 299 |
6 |
Correct |
5 ms |
512 KB |
Correct : C = 4 |
7 |
Partially correct |
7 ms |
640 KB |
Partially correct : C = 350 |
8 |
Correct |
5 ms |
512 KB |
Correct : C = 0 |
9 |
Incorrect |
5 ms |
512 KB |
Wrong |
10 |
Incorrect |
5 ms |
640 KB |
Wrong |
11 |
Partially correct |
7 ms |
640 KB |
Partially correct : C = 370 |
12 |
Correct |
6 ms |
640 KB |
Correct : C = 197 |
13 |
Incorrect |
6 ms |
640 KB |
Wrong |
14 |
Partially correct |
6 ms |
640 KB |
Partially correct : C = 384 |
15 |
Correct |
6 ms |
640 KB |
Correct : C = 239 |
16 |
Correct |
7 ms |
640 KB |
Correct : C = 218 |
17 |
Correct |
5 ms |
512 KB |
Correct : C = 119 |
18 |
Partially correct |
6 ms |
640 KB |
Partially correct : C = 401 |
19 |
Incorrect |
7 ms |
640 KB |
Wrong |
20 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 396 |
21 |
Partially correct |
5 ms |
640 KB |
Partially correct : C = 398 |
22 |
Incorrect |
6 ms |
640 KB |
Wrong |
23 |
Correct |
5 ms |
512 KB |
Correct : C = 236 |
24 |
Correct |
5 ms |
512 KB |
Correct : C = 215 |
25 |
Incorrect |
5 ms |
640 KB |
Wrong |
26 |
Correct |
5 ms |
512 KB |
Correct : C = 117 |
27 |
Incorrect |
6 ms |
640 KB |
Wrong |