int T,N,M;
int f[100010*2];
void init()
{
for (int i = 1; i <= N; i++)
f[i] = i,f[i+N] = i+N;
return;
}
int find(int x)
{
if(x == f[x]) return x;
else
return f[x] = find(f[x]);
}
void unit(int x,int y)
{
x = find(x);
y = find(y);
if (x == y) return;
else f[x] = y;
return ;
}
bool same (int x,int y)
{
x = find(x);
y = find(y);
if (x == y) return true;
else return false;
}
并查集——模板
最新推荐文章于 2024-01-04 14:23:32 发布