Pagini recente » Cod sursa (job #2253932) | Cod sursa (job #497552) | Cod sursa (job #1576224) | Cod sursa (job #1246020) | Cod sursa (job #2115803)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int tata[100005];
int n,m;
int cauta(int x)
{
if(tata[x]==x)
{
return x;
}
int p= cauta(tata[x]);
tata[x]=p;
return p;
}
int main()
{
f>>n>>m;
for(int i=0;i<n;i++)
tata[i]=i;
for(int i=0;i<m;i++)
{
int o,x,y;
f>>o>>x>>y;
if(o==1)
{
x=cauta(x);
y=cauta(y);
tata[y]=x;
}
else
{
x=cauta(x);
y=cauta(y);
if(x==y)g<<"DA";
else g<<"NU";
g<<"\n";
}
}
return 0;
}