Pagini recente » Cod sursa (job #1978951) | Cod sursa (job #2330912) | Cod sursa (job #3240306) | Cod sursa (job #322658) | Cod sursa (job #1898590)
#include <cstdio>
using namespace std;
int t[100005],n,m,i,x,y,cod;
void reuniune(int &x, int &y)
{
while (t[x]!=x) x=t[x];
while (t[y]!=y) y=t[y];
t[y]=x;
}
void raspuns(int &x, int &y)
{
while (t[x]!=x) x=t[x];
while (t[y]!=y) y=t[y];
if (t[x]==t[y]) printf("DA\n");
else printf("NU\n");
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d %d",&n,&m);
for (i=1; i<=n; i++) t[i]=i;
for (i=1; i<=m; i++)
{
scanf("%d %d %d",&cod,&x,&y);
if (cod==1) reuniune(x,y);
if (cod==2) raspuns(x,y);
}
return 0;
}