讨论 / 为什么只有80分 谁帮我下
qw4990 2010-05-26 00:04:00
点我顶贴 收藏 删除
#include<iostream>

using namespace std;

int P,N,M,a[5000];

int root(int i)

{

if(i==a[i]) return i;

else return root(a[i]);

}

main()

{

cin>>P>>N>>M;

for(int i=1;i<=P;i++) a[i]=i;

for(int i=0;i<N;i++)

{

int x,y;

cin>>x>>y;

a[root(x)]=root(y);

}

for(int i=1;i<=P;i++) a[i]=root(a[i]);

for(int i=0;i<M;i++)

{

int x,y;

cin>>x>>y;

if(root(x)==root(y))

cout<<"Yes"<<endl;

else cout<<"No"<<endl;

}

}

查看更多回复
提交回复