#include "island.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
ll n, m;
ll a[100010];
ll pa[100010], ra[100010];
vector<pll> vec[100010];
ll spa[100010][21], mspa[100010][21];
ll dep[100010];
ll ffind(ll here)
{
if(here == pa[here])
return pa[here];
return pa[here] = ffind(pa[here]);
}
void uunion(ll X, ll Y)
{
X = ffind(X);
Y = ffind(Y);
if(X == Y)
return;
if(ra[X] < ra[Y])
pa[X] = Y;
else if(ra[X] > ra[Y])
pa[Y] = X;
else
{
pa[X] = Y;
ra[Y]++;
}
}
void dfs(ll here, ll p)
{
for(auto &i : vec[here])
{
if(i.fi == p)
continue;
dep[i.fi] = dep[here] + 1;
spa[i.fi][0] = here;
mspa[i.fi][0] = i.se;
dfs(i.fi, here);
}
}
void Init(ll K, vector<ll> F, vector<ll> S, vector<ll> E)
{
n = (ll)F.size();
m = (ll)S.size();
for(ll i = 0 ; i < n ; i++)
a[i] = F[i];
for(ll i = 0 ; i < n ; i++)
pa[i] = i;
for(ll i = m - 1 ; i >= 0 ; i--)
{
if(ffind(S[i]) == ffind(E[i]))
continue;
uunion(S[i], E[i]);
vec[S[i]].push_back({E[i], i + 1});
vec[E[i]].push_back({S[i], i + 1});
}
dfs(0, -1);
for(ll i = 1 ; i <= 20 ; i++)
{
for(ll j = 0 ; j < n ; j++)
{
spa[j][i] = spa[spa[j][i - 1]][i - 1];
mspa[j][i] = min(mspa[j][i - 1], mspa[spa[j][i - 1]][i - 1]);
}
}
}
ll Separate(ll A, ll B)
{
ll ans = 987654321;
if(dep[A] < dep[B])
swap(A, B);
ll cha = dep[A] - dep[B];
for(ll i = 20 ; i >= 0 ; i--)
{
if(cha >= (1LL << i))
{
cha -= (1LL << i);
ans = min(ans, mspa[A][i]);
A = spa[A][i];
}
}
if(A == B)
return ans;
for(ll i = 20 ; i >= 0 ; i--)
{
if(spa[A][i] != spa[B][i])
{
ans = min(ans, mspa[A][i]);
ans = min(ans, mspa[B][i]);
A = spa[A][i];
B = spa[B][i];
}
}
ans = min(ans, mspa[A][0]);
ans = min(ans, mspa[B][0]);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
150 ms |
33904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |