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