Pagini recente » Cod sursa (job #352966) | Cod sursa (job #1725881) | Cod sursa (job #2222803) | Cod sursa (job #1945892) | Cod sursa (job #2535003)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[503], n, m;
int main()
{
int i, j, x, y, p, q, op;
fin >> n >> m;
for (i = 1; i <= n; i++)
t[i] = i;
for (i = 1; i <= m; i++)
{
fin >> op >> x >> y;
if (op == 2)
{
if (t[x] == t[y]) fout << "DA"<<endl;
else fout << "NU"<<endl;
}
else
{
if (t[x] != t[y])
{
p = t[x];
q = t[y];
for (j = 1; j <= n; j++)
if (t[j] == p) t[j] = q;
}
}
}
return 0;
}