Pagini recente » Cod sursa (job #1248922) | Cod sursa (job #3264747) | Cod sursa (job #2188088) | Cod sursa (job #2436953) | Cod sursa (job #3279904)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int n, m, T[100010], opp, x, y;
int Find(int i)
{
if(T[i] == 0) return i;
return T[i] = Find(T[i]);
}
inline void Union(int cx, int cy)
{
T[cy] = cx;
}
int main()
{
int cx, cy;
f >> n >> m;
while(m--)
{
f >> opp >> x >> y;
cx = Find(x), cy = Find(y);
if(opp == 1)
if(cx != cy) Union(cx, cy);
else;
else
if(cx == cy) g << "DA\n";
else g << "NU\n";
}
f.close();
g.close();
return 0;
}