Pagini recente » Monitorul de evaluare | Cod sursa (job #3228051) | Cod sursa (job #49096) | Istoria paginii planificare/sedinta-20090216 | Cod sursa (job #1907265)
#include <fstream>
#include <vector>
//#include <iostream>
using namespace std;
ifstream cin ("disjoint.in" );
ofstream cout("disjoint.out");
int s = 0;
vector <int> a;
int main()
{
int n, m, x, y, z;
cin >> n >> m;
a.resize(n + 1);
for (int i = 0; i < a.size(); i++)
a[i] = i;
for (int i = 0; i < m; i++)
{
cin >> z >> x >> y;
if (z == 1)
{//unirea
int q;
while (a[x] != x)
{
q = x;
x = a[x];
a[q] = y;
}
a[x] = y;
}
else
{//afisarea
while (a[x] != x)
x = a[x];
while (a[y] != y)
y = a[y];
if (x == y) cout << "DA\n";
else cout << "NU\n";
}
}
return 0;
}