Pagini recente » Cod sursa (job #3241430) | Cod sursa (job #1030134) | Cod sursa (job #2388925) | Cod sursa (job #2865753) | Cod sursa (job #2109001)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int nmax=100005, mmax=100005;
int n, m;
int father[nmax];
inline void union_find(int x, int y)
{
father[y]=x;
}
inline int root(int node)
{
while(father[node]!=node)
node=father[node];
return node;
}
inline void check_union(int x, int y)
{
if(root(x)==root(y))
fout<<"DA";
else
fout<<"NU";
fout<<'\n';
}
void read_data_and_solve()
{
int x, y, code, i;
fin>>n>>m;
for(i=1;i<=n;i++)
father[i]=i;
for(i=1;i<=m;i++)
{
fin>>code>>x>>y;
if(code==1)
union_find(x,y);
else
check_union(x,y);
}
}
int main()
{
read_data_and_solve();
}