Pagini recente » Cod sursa (job #536427) | Cod sursa (job #782408) | Cod sursa (job #3318004) | Cod sursa (job #2885382) | Cod sursa (job #3317637)
#include <fstream>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int sef[100000];
int bos (int x){
if(sef[x] == x)
return x;
else
return sef[x] = bos(sef[x]);
}
void uni(int x, int y)
{
int sefx = bos(x), sefy = bos(x);
sef[sefy] = sef[sefx];
}
int main()
{
int n, m, c, x, y;
for(int i = 1; i <= n; i++)
sef[i] = i;
cin >> n >> m;
for(int i = 1; i <= m; i++){
cin >> c >> x >> y;
if (c == 1)
unire(x, y);
else{
if (boss(x) == boss(y))
cout << "DA" << '\n';
else
cout << "NU" << '\n';
}
return 0;
}