Pagini recente » Cod sursa (job #1698207) | Cod sursa (job #1722667) | Cod sursa (job #885314) | Cod sursa (job #2193039) | Cod sursa (job #1920858)
#include<bits/stdc++.h>
using namespace std;
const int N_MAX = 1e5 + 5;
int tata[N_MAX], N, M;
int findSet(int x)
{
if( x == tata[x] )
return x;
else return tata[x] = findSet(tata[x]);
}
void Union(int a, int b)
{
int tata_a, tata_b;
tata_a = findSet(a);
tata_b = findSet(b);
tata[tata_a] = tata_b;
}
void read()
{
ifstream in("disjoint.in");
ofstream out("disjoint.out");
in >> N >> M;
for(int i = 1; i <= N; i ++) tata[i] = i;
while(M--)
{
int x, y, test;
in >> test >> x >> y;
if( test == 1 )
Union(x, y);
else{
if( findSet(x) == findSet(y) )
out <<"DA\n";
else out <<"NU\n";
}
}
in.close(); out.close();
}
int main()
{
read();
return 0;
}