Pagini recente » Cod sursa (job #424575) | Cod sursa (job #212942) | Cod sursa (job #878005) | Cod sursa (job #193371) | Cod sursa (job #507928)
Cod sursa(job #507928)
#include<fstream>
using namespace std;
int t[100000],n,m;
int tt(int a)
{
while (t[a]!=a)
a=t[a];
return a;
}
int main()
{
int i,j,x,y,op;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
in>>n>>m;
for (i=1;i<=n;i++)
t[i]=i;
for (i=1;i<=m;i++)
{
in>>op>>x>>y;
if (op==1)
{
t[y]=tt(x);
}
else if (op==2)
{
if (tt(x)!=tt(y))
out<<"NU\n";
else
out<<"DA\n";
}
}
}