#include <bits/stdc++.h>
using namespace std;
#define bit(n,i) ((n>>i)&1)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define ep emplace_back
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
#define ll long long
#define debug(x) cerr << #x << ' ' << x << '\n'
#define dbg(x) cerr<<#x<<' '<<x<<' '
const int base=31;
const int MOD=1e9+7;
const int N=3e5+5;
int ans[N],value[N],lab[N],deg[N],p[N][20],depth[N],n,m;
bool ok[N];
vector<int>adj[N];
int find_set(int v)
{
return (lab[v]==v?v:lab[v]=find_set(lab[v]));
}
bool join(int u,int v,int w)
{
value[n]=w;
deg[u]++;
deg[v]++;
if (deg[u]>=3||deg[v]>=3) ok[n]=1;
u=find_set(u);
v=find_set(v);
adj[n].pb(u);
lab[u]=n;
if (u!=v)
{
adj[n].pb(v);
lab[v]=n;
}
ok[n]|=ok[u]|ok[v];
++n;
}
int lca(int u,int v)
{
if (depth[u]<depth[v]) swap(u,v);
for (int i=18;~i;i--)
{
if (depth[u]-(1<<i)>=depth[v]) u=p[u][i];
}
if (u==v) return u;
for (int i=18;~i;i--)
{
if (~p[u][i]&&p[u][i]!=p[v][i])
{
u=p[u][i];
v=p[v][i];
}
}
return p[u][0];
}
void dfs(int u,int par)
{
if (ok[u]) ans[u]=value[u];
else ans[u]=ans[par];
for (int v:adj[u])
{
if (v==par) continue;
depth[v]=depth[u]+1;
p[v][0]=u;
dfs(v,u);
}
}
void init(int N,int M,int U[],int V[],int W[])
{
n=N,m=M;
for (int i=0;i<n;i++) lab[i]=i;
vector<int>id;
for (int i=0;i<m;i++) id.pb(i);
sort(all(id),[&](int x,int y){return W[x]<W[y];});
for (auto idx:id)
{
join(U[idx],V[idx],W[idx]);
}
for (int i=0;i<n;i++)
{
if (lab[i]!=i) continue;
dfs(i,i);
}
for (int j=1;(1<<j)<n;j++)
{
for (int i=0;i<n;i++)
{
if (~p[i][j-1])
{
p[i][j]=p[p[i][j-1]][j-1];
}
}
}
}
int getMinimumFuelCapacity(int x,int y)
{
return ans[lca(x,y)];
}
Compilation message
swap.cpp: In function 'bool join(int, int, int)':
swap.cpp:41:1: warning: no return statement in function returning non-void [-Wreturn-type]
41 | }
| ^
/usr/bin/ld: /tmp/ccIWRfJk.o: in function `main':
grader.cpp:(.text.startup+0x1c3): undefined reference to `init(int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status