Pagini recente » Cod sursa (job #739753) | Cod sursa (job #252530) | Cod sursa (job #2732472) | Cod sursa (job #290649) | Cod sursa (job #2249665)
#include <bits/stdc++.h>
#define NM 100002
using namespace std;
int n, m;
int T[NM];
int findRoot(int node)
{
if(T[node] == 0)
return node;
return T[node] = findRoot(T[node]);
}
void join(int node1, int node2)
{
node1 = findRoot(node1);
node2 = findRoot(node2);
T[node1] = node2;
}
int main()
{
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
fin >> n >> m;
for(int i = 1; i <= m; i++)
{
int t, a, b;
fin >> t;
fin >> a >> b;
if(t == 1)
{
join(a, b);
}
else
{
bool ok = (findRoot(a) == findRoot(b));
if(ok == 1)
fout << "DA\n";
else
fout << "NU\n";
}
}
return 0;
}