Pagini recente » Istoria paginii utilizator/racsosabe | Cod sursa (job #1489987) | Cod sursa (job #3251056) | Cod sursa (job #1758943) | Cod sursa (job #917814)
Cod sursa(job #917814)
#include<fstream>
#define maxn 100009
using namespace std;
int n,m,T[maxn];
int tata(int x)
{
while(x!=T[x])
x=T[x];
return x;
}
int main()
{
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
fin>>n>>m;
for(int i=1;i<=n;i++)
T[i]=i;
int cod,x,y;
for(;m;--m)
{
fin>>cod>>x>>y;
x=tata(x);
y=tata(y);
if ( cod == 1 )
T[x] = y;
else
if ( x == y )
fout << "DA" << '\n';
else
fout << "NU" << '\n';
}
return 0;
}