Pagini recente » Cod sursa (job #2040652) | Cod sursa (job #2159852) | Cod sursa (job #162136) | Cod sursa (job #2046303)
#include <fstream>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout("disjoint.out");
int tata[100005];
inline int dad(int x)
{
if(tata[x] == x) return x;
else return tata[x] = dad(tata[x]);
}
void unite(int x, int y)
{
int tx, ty;
tx = dad(x);
ty = dad(y);
tata[tx] = ty;
}
int main()
{
int n, m, op, x, y;
fin >> n >> m;
for(int i = 1; i <= n; ++i) tata[i] = i;
while(m--)
{
fin >> op >> x >> y;
if(op == 1) unite(x, y);
else
if(dad(x) == dad(y))
fout << "DA\n";
else
fout << "NU\n";
}
fin.close(); fout.close();
return 0;
}