#include "lokahia.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int used[222];
int rtnumber[222];
struct DSU
{
int S;
struct node
{
int p; ll sum;
};
vector<node> dsu;
DSU(int n)
{
S = n;
for(int i = 0; i < n; i++)
{
node tmp;
tmp.p = i; tmp.sum = 0;
dsu.pb(tmp);
}
}
void reset(int n)
{
dsu.clear();
S = n;
for(int i = 0; i < n; i++)
{
node tmp;
tmp.p = i; tmp.sum = 0;
dsu.pb(tmp);
}
}
int rt(int u)
{
if(dsu[u].p == u) return u;
dsu[u].p = rt(dsu[u].p);
return dsu[u].p;
}
void merge(int u, int v)
{
u = rt(u); v = rt(v);
if(u == v) return ;
if(rand()&1) swap(u, v);
dsu[v].p = u;
dsu[u].sum += dsu[v].sum;
}
bool sameset(int u, int v)
{
if(rt(u) == rt(v)) return true;
return false;
}
ll getstat(int u)
{
return dsu[rt(u)].sum;
}
};
map<ii,int> ma;
int ask(int u, int v)
{
if(u==v) return u;
if(ma.find({u,v})!=ma.end()) return ma[{u,v}];
return (ma[{u,v}]=ma[{v,u}]=CollectRelics(u,v));
}
int FindBase(int N)
{
int n=N;
if(n==1) return 0;
if(n==2)
{
return ask(0,1);
}
memset(used,0,sizeof(used));
vector<pair<vi,vi> > cmps;
pair<vi,vi> cur;
for(int i=0;i<n;i++)
{
if(cur.fi.empty())
{
cur.fi.pb(i); continue;
}
int newrt = ask(cur.fi[0],i);
if(newrt==-1)
{
cur.se.pb(i);
}
else
{
cur.fi.pb(i);
cur.fi[0]=newrt;
}
if(cur.fi.size()==cur.se.size())
{
cmps.pb(cur); cur={{},{}};
}
}
if(cur.fi.empty())
{
return -1;
}
cmps.pb(cur);
int u = cmps.back().fi[0];
int cnt=0;
for(auto V:cmps)
{
int rt = ask(V.fi[0],u);
if(rt==-1)
{
for(int x:V.se)
{
rt = ask(x,u);
if(rt!=-1)
{
u=rt; cnt++;
}
}
}
else
{
cnt+=V.fi.size();
u=rt;
}
}
if(cnt*2>n) return u;
else return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Correct : C = 120 |
2 |
Correct |
2 ms |
632 KB |
Correct : C = 100 |
3 |
Correct |
3 ms |
632 KB |
Correct : C = 200 |
4 |
Correct |
3 ms |
632 KB |
Correct : C = 247 |
5 |
Correct |
2 ms |
632 KB |
Correct : C = 161 |
6 |
Correct |
3 ms |
632 KB |
Correct : C = 203 |
7 |
Correct |
3 ms |
632 KB |
Correct : C = 197 |
8 |
Correct |
3 ms |
636 KB |
Correct : C = 297 |
9 |
Correct |
2 ms |
504 KB |
Correct : C = 119 |
10 |
Correct |
3 ms |
636 KB |
Correct : C = 197 |
11 |
Correct |
2 ms |
376 KB |
Correct : C = 0 |
12 |
Correct |
3 ms |
556 KB |
Correct : C = 255 |
13 |
Correct |
3 ms |
632 KB |
Correct : C = 198 |
14 |
Correct |
2 ms |
632 KB |
Correct : C = 117 |
15 |
Correct |
3 ms |
632 KB |
Correct : C = 204 |
16 |
Correct |
2 ms |
508 KB |
Correct : C = 118 |
17 |
Correct |
3 ms |
632 KB |
Correct : C = 111 |
18 |
Correct |
3 ms |
632 KB |
Correct : C = 118 |
19 |
Correct |
3 ms |
632 KB |
Correct : C = 199 |
20 |
Correct |
2 ms |
632 KB |
Correct : C = 117 |
21 |
Correct |
2 ms |
504 KB |
Correct : C = 4 |
22 |
Correct |
3 ms |
632 KB |
Correct : C = 194 |
23 |
Correct |
2 ms |
632 KB |
Correct : C = 175 |
24 |
Correct |
2 ms |
632 KB |
Correct : C = 177 |
25 |
Correct |
2 ms |
632 KB |
Correct : C = 60 |
26 |
Correct |
3 ms |
632 KB |
Correct : C = 189 |
27 |
Correct |
3 ms |
632 KB |
Correct : C = 198 |