Pagini recente » Cod sursa (job #1070713) | Cod sursa (job #2088593) | Cod sursa (job #2221695) | Cod sursa (job #2197324) | Cod sursa (job #2090012)
#include <fstream>
using namespace std;
int t[100001];
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int tata(int x)
{
if (t[x]!=x)
t[x]=tata(t[x]);
return t[x];
}
void join(int x,int y)
{
int rx=tata(x);
t[rx]=y;
}
int main()
{
int n,m,tip,x,y;
in>>n>>m;
for (int i=1;i<=n;i++)
t[i]=i;
for (int i=1;i<=m;i++)
{
in>>tip>>x>>y;
if (tip==1)//reuniune
join(x,y);
else //intrebare
if (tata(x)==tata(y))
out<<"DA\n";
else
out<<"NU\n";
}
return 0;
}