Pagini recente » Cod sursa (job #198796) | Cod sursa (job #294716) | Cod sursa (job #199336) | Cod sursa (job #2565858) | Cod sursa (job #1359837)
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int N=100001;
int t[N];
int tip, x, y;
int n, m;
int radacina (int x)
{
if(t[x] == 0)
return x;
t[x]=radacina(t[x]);
return t[x];
}
void citire ()
{
f >> n >> m;
for(int i=1; i<=m; i++)
{
f >> tip >> x >> y;
if(tip == 1)
{
x = radacina(x);
y = radacina(y);
t[x]=y;
}
if(tip == 2)
{
if(radacina(x) == radacina(y))
g << "DA" << '\n';
else
g << "NU" << '\n';
}
}
}
int main ()
{
citire ();
return 0;
}