Pagini recente » Cod sursa (job #22454) | Cod sursa (job #2611014) | Cod sursa (job #857319) | Cod sursa (job #2718161) | Cod sursa (job #1119016)
#include <fstream>
#define MX 100001
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m;
int l[MX];
int Find(int x)
{
int t=l[x];
if(l[x]==0) return x;
while(l[t] != 0)
{
if(l[t]==0) break;
t = l[t];
}
l[x] = t;
return t;
}
void Union(int x, int y)
{
l[Find(x)] = Find(y);
}
int main()
{
int i,cod,x,y;
fin>>n>>m;
for(i=1; i<=m; i++)
{
fin>>cod>>x>>y;
if(cod==1)
{
Union(x, y);
}
else
{
if(Find(x) == Find(y))
{
fout<<"DA\n";
}
else
{
fout<<"NU\n";
}
}
}
fin.close(); fout.close();
return 0;
}