Pagini recente » Cod sursa (job #789850) | Cod sursa (job #711842) | Cod sursa (job #1028356) | Cod sursa (job #1131184) | Cod sursa (job #1345801)
#include <fstream>
#define nmax 100005
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[nmax],n,m;
void uneste(int x,int y)
{
t[t[x]]=t[y];
}
int tata(int x)
{
if(t[x]==x)
return x;
t[x]=tata(t[x]);
return t[x];
}
int main()
{
fin>>n>>m;
int cod,x,y;
for(int i=1;i<=n;i++)
t[i]=i;
for(int i=1;i<=m;i++)
{
fin>>cod>>x>>y;
if(cod==1)
uneste(t[x],t[y]);
else
if(tata(x)==tata(y))
fout<<"DA\n";
else
fout<<"NU\n";
}
return 0;
}