Ren·Ashbell @ 2017-09-23 09:35:09
#include<iostream>
#define MAX 10001
using namespace std;
struct node
{
int left;
int right;
int zi;
};
int m,n,father[MAX];
int find_father(int kind)
{
if(father[kind]==kind)
return kind;
else
{
father[kind]=find_father(father[kind]);
return father[kind];
}
}
void find_conset(int l,int r)
{
int ti,tj;
ti=find_father(ti);
tj=find_father(tj);
if(ti==tj)
return;
else
father[tj]=ti;
}
bool find_cheat(int l,int r)
{ int ti,tj;
ti=find_father(ti);
tj=find_father(tj);
if(ti==tj)
return 1;
else
return 0;
}
int main()
{ node ciol[MAX];
cin>>n>>m;
for(int i=1;i<=n;i++)
father[i]=i;
for(int i=1;i<=m;i++)
cin>>ciol[i].zi>>ciol[i].left>>ciol[i].right;
for(int i=1;i<=m;i++)
{
if(ciol[i].zi==1)
find_conset(ciol[i].left,ciol[i].right);
if(ciol[i].zi==2)
{
if(find_cheat(ciol[i].left,ciol[i].right)==true)
cout<<"Y";
if(find_cheat(ciol[i].left,ciol[i].right)==false)
cout<<"N";
}
}
}
by Ren·Ashbell @ 2017-09-23 14:09:31
已解决