Pagini recente » Cod sursa (job #642433) | Cod sursa (job #227489) | Cod sursa (job #522011) | Cod sursa (job #1934088) | Cod sursa (job #955339)
Cod sursa(job #955339)
#include <fstream>
using namespace std;
#define NMAX 100005
int t[NMAX],n,m;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int tata(int nod)
{
if(t[nod] == 0)
return nod;
return tata(t[nod]);
}
int main()
{
int cod,x,y,a,b;
fin>>n>>m;
for(int i=0;i<m;i++)
{
fin>>cod>>x>>y;
a=tata(x);
b=tata(y);
if(cod==1)
t[b]=a;
if(cod==2)
if(a==b)
fout<<"DA\n";
else
fout<<"NU\n";
}
}