Pagini recente » Monitorul de evaluare | Cod sursa (job #895068) | Istoria paginii runda/lab10d30mai2014 | Cod sursa (job #450160) | Cod sursa (job #1885139)
#include <fstream>
#define lmax 100005
using namespace std;
int n,m,x,i,p[lmax],cod,y;
int str(int x)
{
while(x!=p[x])x=p[x];
return x;
}
int main()
{
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
fin>>n>>m;
for(i=1;i<=n;i++)
p[i]=i;
for(i=1;i<=m;i++)
{
fin>>cod>>x>>y;
if(cod==1)
p[str(x)]=p[str(y)];
else
{
if(str(x)==str(y))fout<<"DA\n";
else fout<<"NU\n";
}
}
return 0;
}