Pagini recente » Cod sursa (job #2114696) | Cod sursa (job #162049) | Cod sursa (job #1234159) | Cod sursa (job #751951) | Cod sursa (job #2497374)
#include<fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m;
int main()
{
fin >> n >> m;
int* dis = new int[n + 1];
for (int i = 1; i <= n; i++)
dis[i] = i;
int op, x, y;
while (m--)
{
fin >> op >> x >> y;
int aux1 = x, aux2 = y;
while (dis[aux1] != aux1)
aux1 = dis[aux1];
while (dis[aux2] != aux2)
aux2 = dis[aux2];
if (op == 1)
{
if (aux1 < aux2)
dis[y] = x;
else
dis[x] = y;
}
else
if (aux1 != aux2)
fout << "NU\n";
else
fout << "DA\n";
}
delete[] dis;
return 0;
}