Pagini recente » Cod sursa (job #2089786) | Cod sursa (job #582464) | Cod sursa (job #247342) | Cod sursa (job #731077) | Cod sursa (job #1379121)
#include <fstream>
#include <vector>
using namespace std;
ifstream is("disjoint.in");
ofstream os("disjoint.out");
int n, m;
int type, x, y;
int p[100001];
int h[100001];
void Solve();
void Union(int x, int y);
int Find(int x);
int main()
{
Solve();
is.close();
os.close();
return 0;
}
void Solve()
{
is >> n >> m;
for ( int i = 1; i <= n; ++i )
p[i] = i;
for ( int i = 1; i <= m; ++i )
{
is >> type >> x >> y;
switch(type)
{
case 1 :
Union(Find(x), Find(y));
break;
case 2 :
if ( Find(x) == Find(y) )
os << "DA" << '\n';
else
os << "NU" << '\n';
break;
}
}
}
void Union(int x, int y)
{
p[x] = y;
}
int Find(int x)
{
if ( x != p[x] )
p[x] = Find(p[x]);
return p[x];
}