Pagini recente » Rating Stefan Avram (sebyza) | Cod sursa (job #1328708) | Cod sursa (job #1656693) | Cod sursa (job #923262) | Cod sursa (job #527085)
Cod sursa(job #527085)
#include <fstream>
#define nmax 100042
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int T[nmax];
inline int multime(int nod)
{
while(T[nod])
nod=T[nod];
return nod;
}
int main()
{
int N,M,x,y,op,m1,m2;
in>>N>>M;
while(M--)
{
in>>op>>x>>y;
m1=multime(x);
m2=multime(y);
if(op==1)
T[m1]=m2;
else
if(m1==m2)
out<<"DA\n";
else out<<"NU\n";
}
return 0;
}