Pagini recente » Cod sursa (job #1974875) | Cod sursa (job #2925340) | Cod sursa (job #2748771) | Cod sursa (job #1533891) | Cod sursa (job #902954)
Cod sursa(job #902954)
#include <fstream>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int a[100000],e,f,i,l,x,y,h,n,m;
int tata(int c)
{
if(c==a[c]) return c;
return tata(a[c]);
}
int main()
{
in>>n>>m;
for(i=1;i<=n;i++) a[i]=i;
for(l=1;l<=m;l++)
{
in>>h>>x>>y;
e=tata(x);
f=tata(y);
if(h==1&&e!=f) a[e]=f;
if(h==2)
{
if(e==f) out<<"DA\n";
else out<<"NU\n";
}
}
return 0;
}