Pagini recente » Cod sursa (job #2887964) | Cod sursa (job #745098) | Cod sursa (job #1581609) | Cod sursa (job #1350167) | Cod sursa (job #2108957)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int nmax=100005, mmax=100005;
int n, m;
int vis[nmax];
inline void union_find(int x, int y)
{
int i, mark;
mark=vis[y];
if(vis[x]!=vis[y])
vis[y]=x;
else
return;
for(i=1;i<=n;i++)
{
if(vis[i]==mark)
vis[i]=x;
}
}
inline void check_union(int x, int y)
{
if(vis[x]==vis[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++)
vis[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();
}