Pagini recente » Cod sursa (job #3269952) | Cod sursa (job #635759) | Cod sursa (job #2118234) | Cod sursa (job #1902118) | Cod sursa (job #1166380)
#include <iostream>
#include <fstream>
using namespace std;
ifstream d("disjoint.in");
ofstream o("disjoint.out");
const int N=1e6+1;
int *tata;
void uunion(int x,int y)
{
tata[x]=y;
}
int findd(int x)
{
if(x != tata[x])
return findd(tata[x]);
return x;
}
int main()
{
int cod,x,y;
d>>x>>y;
// cout << "x = " << x << endl;
tata=new int[x + 1];
//return 0;
for(int i=1;i<=x;i++)
tata[i]=i;
while(d>>cod>>x>>y)
{
if(cod==1)
uunion(x,y);
else
{
if(findd(x)==findd(y))
o<<"DA\n";
else
o<<"NU\n";
}
}
return 0;
}