Pagini recente » Cod sursa (job #2101458) | Cod sursa (job #688794) | Cod sursa (job #1951813) | Cod sursa (job #1193296) | Cod sursa (job #2832333)
#include <iostream>
#include<fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int theRoots[1000005];
int main()
{
int n,m;
fin>>n>>m;
for(int i=1; i<=n; i++)
theRoots[i] = i;
for(int i=0; i<m; i++)
{
int t,x,y;
fin>>t>>x>>y;
if(t == 1)
{
if(theRoots[x] != theRoots[y])
{
for(int j=1; j<=n; j++)
if(theRoots[j] == theRoots[y])
theRoots[j] = theRoots[x];
}
}
else
{
if(theRoots[x] != theRoots[y])
fout<<"NU"<<'\n';
else
fout<<"DA"<<'\n';
}
}
fin.close();
fout.close();
return 0;
}