Pagini recente » Monitorul de evaluare | Istoria paginii runda/ioi_training/clasament | Monitorul de evaluare | Istoria paginii runda/preojigim/clasament | Cod sursa (job #2142247)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[100001];
int root(int x) {return t[x] ? t[x] = root(t[x]) : x;}
int main()
{
int n, m, cod, x, y;
fin >> n >> m;
while (m--)
{
fin >> cod >> x >> y;
if (cod == 1) t[root(x)] = root(y);
else
{
if (root(x) == root(y)) fout << "DA\n";
else fout << "NU\n";
}
}
}