Pagini recente » Cod sursa (job #2299373) | Cod sursa (job #3197050) | Cod sursa (job #1724426) | Cod sursa (job #2773919) | Cod sursa (job #3004124)
#include<bits/stdc++.h>
using namespace std;
const int nmax=100000;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int t[nmax+1];
int n;
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 m,op,x,y,cx,cy;
f>>n>>m;
while(m--)
{
f>>op>>x>>y;
cx=Find(x);
cy=Find(y);
if(op==1)
{
if(cx!=cy) Union(cx,cy);
}
else
{
if(cx==cy) g<<"DA\n";
else g<<"NU\n";
}
}
}