Pagini recente » Cod sursa (job #1893580) | Cod sursa (job #1873912) | Cod sursa (job #1201688) | Cod sursa (job #2910103) | Cod sursa (job #2152416)
#include <fstream>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int parent[100005],n,m;
int Find( int x )
{
if( parent[x] == x )
{
return x;
}
return Find( parent[x]);
}
void Union( int x, int y )
{
int a = Find(x);
int b = Find(y);
parent[a] = b;
}
int main()
{
in >> n >> m ;
for(int i=1; i<=n; i++) parent[i] = i;
int qw, x,y;
for(int i=1; i<=m; i++)
{
in >> qw >> x >> y;
if( qw == 1 )
Union(x,y); else
if( Find(x) != Find(y) ) out << "NU" <<'\n'; else out << "DA" << '\n';
}
return 0;
}