Pagini recente » Cod sursa (job #634774) | Cod sursa (job #3276781) | Cod sursa (job #3173738) | Cod sursa (job #3166060) | Cod sursa (job #2432507)
#include <fstream>
#define NMAX 100100
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int tata[NMAX];
int n, m, i, a, b, c;
int find(int nod)
{
if(tata[nod] == nod) return nod;
tata[nod] = find(tata[nod]);
return tata[nod];
}
void unionn(int x, int y)
{
int tx, ty;
tx = find(x);
ty = find(y);
if(tx != ty) tata[ty] = tx;
else tata[tx] = ty;
}
int main()
{
f >> n >> m;
for(i = 1; i <= n; i ++)
tata[i] = i;
for(i = 1; i <= m; i ++)
{
f >> a >> b >> c;
if(a == 1)
unionn(b, c);
else
if(find(b) == find(c))
g << "DA" << "\n";
else
g << "NU" << "\n";
}
return 0;
}