Pagini recente » Cod sursa (job #809593) | Cod sursa (job #2421742) | Cod sursa (job #625157) | Cod sursa (job #59485) | Cod sursa (job #2575180)
#include <fstream>
using namespace std;
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int tata[100001];
int sef(int x)
{
if(x==tata[x])return x;
else return tata[x]=sef(tata[x]);
}
void unire(int x,int y)
{
int sefx,sefy;
sefx=sef(x);
sefy=sef(y);
tata[sefx]=sefy;
}
int main()
{
int n,m,i,cod,x,y;
cin>>n>>m;
for(i=1;i<=n;i++)
{
tata[i]=i;
}
for(i=1;i<=m;i++)
{
cin>>cod>>x>>y;
if(cod==2)
if(sef(x)==sef(y))cout<<"DA"<<endl;
else cout<<"NU"<<endl;
if(cod==1)unire(x,y);
}
return 0;
}