Pagini recente » Cod sursa (job #1351372) | Cod sursa (job #2482825) | Cod sursa (job #2221345) | Monitorul de evaluare | Cod sursa (job #2553053)
#include <bits/stdc++.h>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
const int Nmax = 100001;
vector <int> t(Nmax);
int q,n,m,x,y;
void update()
{
for(int i = 1; i <= n; ++i)
if(t[i] == y) t[i] = x;
}
int main()
{
in >> n >> m;
while(m--)
{
in >> q >> x >> y;
if(q == 1)
{
if(!t[x])
t[x] = x;
if(!t[y])
t[y] = x;
update();
}
else
{
if(t[x] == t[y])
out << "DA" << '\n';
else
out << "NU" << '\n';
}
}
return 0;
}