Pagini recente » Cod sursa (job #2278806) | Cod sursa (job #1436315) | Cod sursa (job #2390588) | Cod sursa (job #589799) | Cod sursa (job #1416373)
#include <fstream>
using namespace std;
ifstream is("disjoint.in");
ofstream os("disjoint.out");
#define MAX 100002
int n, m, a[MAX], c, x, y;
void SetRoot()
{
for ( int i = 1; i <= m; ++i )
a[i] = i;
}
int GetRoot( int x )
{
if ( a[x] == x )
return x;
int root = GetRoot(a[x]);
a[x] = root;
return root;
}
int main()
{
is >> n >> m;
SetRoot();
for ( int i = 1; i <= m; ++i )
{
is >> c >> x >> y;
if ( c == 1 )
a[GetRoot(x)] = GetRoot(y);
else
{
if( GetRoot(x) == GetRoot(y) )
os << "DA\n";
else
os << "NU\n";
}
}
is.close();
os.close();
return 0;
}