Pagini recente » Cod sursa (job #2354797) | Cod sursa (job #727894) | Cod sursa (job #427241) | Cod sursa (job #2442653) | Cod sursa (job #2766654)
#include <bits/stdc++.h>
#define DAU ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PLEC return 0;
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
#define cin fin
#define cout fout
#define N 100005
int t[N], r[N], n, m, cerinta, x, y;
int caut(int nod)
{
if(nod != r[nod])
{
r[nod] = caut(r[nod]);
}
return r[nod];
}
void unire(int x, int y)
{
int rx = caut(x),
ry = caut(y);
if(rx != ry)r[rx] = ry;
}
int main()
{
DAU
cin >> n >> m;
for(int i = 1 ; i <= n ; i++)r[i] = i;
for(int i = 1 ; i <= m ; i++)
{
cin >> cerinta >> x >> y;
if(cerinta == 1)
{
unire(x,y);
}
else
{
if(caut(x) != caut(y))cout << "NU\n";
else cout << "DA\n";
}
}
PLEC
}