Pagini recente » Cod sursa (job #316567) | Cod sursa (job #2380538) | Cod sursa (job #2536783) | Cod sursa (job #1832447) | Cod sursa (job #612788)
Cod sursa(job #612788)
#include <fstream>
#include <cstring>
#define TSize 100001
using namespace std;
ifstream in;
ofstream out;
int T[TSize];
inline int root(int x)
{
if(T[x]!=x) T[x]=root(T[x]);
return T[x];
}
int main()
{
int M,N,cod,x,y,cnt=0;
memset(T,0,sizeof(T));
in.open("disjoint.in");
out.open("disjoint.out");
in>>N>>M;
for(int i=1;i<=N;++i) T[i]=i;
for(;M--;)
{
in>>cod>>x>>y;
if(cnt<N)
{
x=root(x);
y=root(y);
}
if(cod==1) T[x]=y,++cnt;
else (x==y) ? out<<"DA\n" : out<<"NU\n";
}
in.close();
out.close();
return 0;
}