Pagini recente » Cod sursa (job #2777218) | Cod sursa (job #1999273) | Cod sursa (job #2115592) | Cod sursa (job #472362) | Cod sursa (job #2200601)
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int m, t[100002];
inline int tata(int x)
{
while(t[x])
x=t[x];
return x;
}
void unite(int x, int n2)
{
int y=tata(n2);
while(t[x])
{
n2=t[x];
t[x]=y;
x=n2;
}
t[x]=y;
}
int main()
{
int op, x, y;
f>>m>>m;
while(f>>op>>x>>y)
{
if(op==1)
unite(x, y);
else if(tata(x)==tata(y))
g<<"DA\n";
else
g<<"NU\n";
}
return 0;
}