Pagini recente » Cod sursa (job #109278) | Cod sursa (job #230093) | Cod sursa (job #3267034) | Cod sursa (job #2495047) | Cod sursa (job #2152420)
#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 )
{
x = Find(x);
y = Find(y);
parent[x] = y;
}
int main()
{
ios::sync_with_stdio(0);
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;
}