Pagini recente » Cod sursa (job #2670627) | Cod sursa (job #1877122) | Cod sursa (job #1778285) | Cod sursa (job #1995037) | Cod sursa (job #2215837)
#include <bits/stdc++.h>
#define lim 100005
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int n, m, operation_Type, first_Node, second_Node;
int father[lim];
int parent( int node)
{
if ( node == father[node] )
return node;
father[node] = parent(father[node]);
return father[node];
}
void unite (int node_X, int node_Y)
{
father[parent(node_X)] = parent(node_Y);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
fin>>n>>m;
for ( int i = 1; i <= n; ++i )
father[i] = i;
for ( int i = 1; i <= m; ++i )
{
fin>>operation_Type>>first_Node>>second_Node;
if ( operation_Type == 1 )
unite(first_Node, second_Node);
else
if ( parent(first_Node) == parent(second_Node) )
fout<<"DA"<<'\n';
else
fout<<"NU"<<'\n';
}
}