Pagini recente » Cod sursa (job #320340) | Cod sursa (job #285752) | Cod sursa (job #11576) | Cod sursa (job #245206) | Cod sursa (job #2549353)
#include <bits/stdc++.h>
#define NMAX 100005
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int tata[NMAX],n,m;
int root(int node)
{
if(tata[node]==0) return node;
tata[node]=root(tata[node]);
return tata[node];
}
void unite(int x, int y)
{
tata[x]=root(y);
}
int main()
{
f>>n>>m;
int i,x,y,c;
for(i=1;i<=m;i++)
{
f>>c>>x>>y;
if(c==2)
{
if(root(x)==root(y)) g<<"DA\n";
else g<<"NU\n";
}
else unite(x,y);
}
return 0;
}