Pagini recente » Cod sursa (job #2431628) | Cod sursa (job #1524383) | Cod sursa (job #165895) | Cod sursa (job #2800367) | Cod sursa (job #1746555)
#include <bits/stdc++.h>
#define Nmax 100005
using namespace std;
int t[Nmax], n;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
void Union(int x, int y)
{
t[y] = x;
}
int Find(int x)
{
int rad, aux;
rad = x;
while(t[rad] != 0)
rad = t[rad];
while(x != rad)
{
aux = t[x];
t[x] = rad;
x = aux;
}
return rad;
}
void Rezolv()
{
int x, y, m, op;
f >> n >> m;
for(int i = 1; i <= m; i++)
{
f >> op >> x >> y;
x = Find(x);
y = Find(y);
if(op == 1)
{
if(x != y) Union(x, y);
}
else
{
if(x == y) g << "DA\n";
else g << "NU\n";
}
}
f.close();
g.close();
}
int main()
{
Rezolv();
return 0;
}