Pagini recente » Diferente pentru warm-up-2019/solutii/shoturi intre reviziile 99 si 52 | Diferente pentru preoni-2007/runda-3/solutii intre reviziile 8 si 9 | Statistici Hanzu Radu (HanzuRadu) | Istoria paginii utilizator/samson.theodor | Cod sursa (job #376656)
Cod sursa(job #376656)
/*
* File: main.cpp
* Author: virtualdemon
*
* Created on December 22, 2009, 10:48 AM
*/
#include <vector>
#include <fstream>
/*
*
*/
using namespace std;
vector<unsigned int> father;
inline unsigned int find( unsigned int x )
{
if( father[x] == x )
return x;
return find( father[x] );
}
inline void unification( unsigned int x, unsigned int y )
{
father[x]=father[y]=min( x, y );
}
int main()
{unsigned int n, t, i, op, x, y, minim;
ifstream in("disjoint.in");
in>>n>>t;
father.resize(n);
for( i=0; i < n; ++i )
father[i]=i;
ofstream out("disjoint.out");
for( i=0; i < t; ++i )
{
in>>op>>x>>y;
x-=1;
y-=1;
if( 1 == op )
{
unification( find(x), find(y) );
continue;
}
if( find(x) == find(y) )
out<<"DA\n";
else out<<"NU\n";
}
return 0;
}