Pagini recente » Cod sursa (job #353821) | Cod sursa (job #1924138) | Cod sursa (job #1718932) | Cod sursa (job #1046223) | Cod sursa (job #1394535)
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int super[100005];
int find (int nod)
{
if(super[nod]==nod)
return nod;
else
{
super[nod]=find(super[nod]);
return super[nod];
}
}
void unire (int x, int y)
{
int sx,sy;
sx=find(x);
sy=find(y);
super[sy]=sx;
}
int main()
{
int n,m,i,op,x,y;
f>>n>>m;
for(i=1;i<=n;i++)
super[i]=i;
for(i=1;i<=m;i++)
{
f>>op>>x>>y;
if(op==1)
unire(x,y);
else
if(find(x)!=find(y))
g<<"NU"<<endl;
else g<<"DA"<<endl;
}
return 0;}