• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

qkzzjn0h0mh4228.png

单击以查看代码#includeiostream。

使用命名空间std

const int N=1e5 10

int p[N];

int find(int x)

{

if (p[x]!=x)p[x]=find(p[x]);

return p[x];

}

int main()

{

int n,m;

CIN nm;

for(int I=1;I=n;I)p=I;

while (m - ) {

char op

int a,b;

cin执行部分a b;

if(op==' M ')p[find(a)]=find(b);

否则{

if(find(a)==find(b))puts(' Yes ');

else puts(' No ');

}

}

返回0;

}

P[ x]用于存储x的父节点号,根节点满足P[x]=x;

find的作用是返回根节点的值,将路径上所有点的父节点变成根节点(路径压缩);

合并集合a和集合b,将集合a根节点改为集合b的根节点的子节点;

Link to comment
Share on other sites