Pagini recente » Borderou de evaluare (job #2830580) | Cod sursa (job #2571913) | Cod sursa (job #1312182) | Cod sursa (job #1084356) | 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;
}