Pagini recente » Cod sursa (job #1920523) | Cod sursa (job #262782) | Cod sursa (job #1974604) | Cod sursa (job #1867581) | Cod sursa (job #3134981)
#include <fstream>
using namespace std;
const int N = 100000;
int t[N + 1];
int main()
{
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int n, m;
in >> n >> m;
for (int i = 1; i <= n; i ++)
{
t[i] = i;
}
for (int i = 0; i < m; i ++)
{
int cod, x, y;
in >> cod >> x >> y;
if (cod == 1)
{
int bun = t[x], rau = t[y];
for (int i = 1; i <= n; i ++)
{
if (t[i] == rau)
{
t[i] = bun;
}
}
}
else
{
if (t[x] == t[y])
{
out << "DA\n";
}
else
{
out << "NU\n";
}
}
}
in.close();
out.close();
return 0;
}