Pagini recente » Cod sursa (job #699037) | Cod sursa (job #2967770) | Cod sursa (job #1733696) | Cod sursa (job #2439055) | Cod sursa (job #1893370)
#include<bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 5;
int tati[NMAX];
int findSet(int x)
{
if( tati[x] == x )
return x;
return tati[x] = findSet(tati[x]);
}
void Union(int el1, int el2)
{
int tata_el1, tata_el2;
tata_el1 = findSet(el1);
tata_el2 = findSet(el2);
tati[tata_el1] = tata_el2;
}
int main()
{
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int n, m;
f >> n >> m;
for(int i = 1; i <= n; i++)
tati[i] = i;
for(int i = 1; i <= m; i++)
{
int t, x, y;
f >> t >> x >> y;
if ( t == 1 )
Union(x, y);
else
{
if( findSet(x) == findSet(y) )
g << "DA\n";
else g << "NU\n";
}
}
return 0;
}