Pagini recente » Autentificare | Cod sursa (job #508933) | Cod sursa (job #75745) | Cod sursa (job #42498) | Cod sursa (job #1468464)
#include<fstream>
#include<time.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int *sp;
int findsp(int x)
{
if(sp[x]==x)
return x;
else
return sp[x]=findsp(sp[x]);
}
void unite(int x,int y)
{
int tx,ty;
tx=findsp(x);
ty=findsp(y);
sp[tx]=ty;
}
int main()
{
int n,m,o,x,y,i;
f>>n;
f>>m;
sp=new int[n+1];
for(i=1;i<=n;i++)
sp[i]=i;
while(f>>o>>x>>y)
{
if(o==1)
unite(x,y);
if(o==2)
{
int tx=findsp(x);
int ty=findsp(y);
if(tx==ty)
g<<"DA";
else
g<<"NU";
g<<"\n";
}
}
return 0;
}