Pagini recente » Atasamentele paginii Voteaza Gigel | Profil NataliaLorena | Cod sursa (job #2234865) | Rating Denisa (Dennn) | Cod sursa (job #2563587)
#include<fstream>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int n, m, t[100010];
int f (int a)
{
if (a==t[a])return a;
else return f(t[a]);
}
int main ()
{
int i, c, x, y;
fin>>n>>m;
for (i=1; i<=n; i++)t[i]=i;
for (i=1; i<=m; i++)
{
fin>>c>>x>>y;
if (c==1)
t[f(x)]=f(y);
else
{
if (f(x)==f(y))fout<<"DA"<<'\n';
else fout<<"NU"<<'\n';
}
}
}