Pagini recente » Cod sursa (job #2000358) | Istoria paginii runda/ten1 | Cod sursa (job #974654) | Cod sursa (job #2038524) | Cod sursa (job #825083)
Cod sursa(job #825083)
#include<fstream>
#define NN 100010
using namespace std;
ofstream out("disjoint.out");
int T[NN],n,m;
void read();
void preprocesez();
void unire(int x,int y);
int find(int x);
int main()
{
read();
return 0;
}
void preprocesez()
{
for(int i=1;i<=n;i++)
T[i]=i;
}
int find(int x)
{
if ( x != T[x])
T[x]= find (T[x]);
return T[x];
}
void unire(int x,int y)
{
T[find(x)] = find(y);
}
void read()
{
ifstream in("disjoint.in");
in>>n>>m;
preprocesez();
for(int cod,x,y ; m ; --m )
{
in>>cod>>x>>y;
if ( cod == 1)
unire(x,y);
else
if (find(x) == find(y))
out<<"DA"<<'\n';
else
out<<"NU"<<'\n';
}
}