Pagini recente » Cod sursa (job #1468658) | Cod sursa (job #994117) | Cod sursa (job #1788622) | Cod sursa (job #1110854) | Cod sursa (job #2278784)
#include <fstream>
using namespace std;
int T[100001];
ifstream in ("disjoint.in");
ofstream out("disjoint.out");
int sef(int x){
if(x!=T[x])
T[x]=sef(T[x]);
return T[x];
}
void join(int x,int y){
int t1=sef(x),t2=sef(y);
T[t2]=t1;
}
bool q1(int x,int y){
int t1=sef(x),t2=sef(y);
if(t1==t2)
return 1;
return 0;
}
int main()
{
int n,m,i,c,x,y;
in>>n>>m;
for(i=1;i<=n;i++)
T[i]=i;
for(i=1;i<=m;i++){
in>>c>>x>>y;
if(c==1)
join(x,y);
else
if(q1(x,y)==1)
out<<"DA\n";
else
out<<"NU\n";
}
return 0;
}