Pagini recente » Cod sursa (job #2554583) | Cod sursa (job #140314) | Cod sursa (job #754032) | Cod sursa (job #1774717) | Cod sursa (job #1609301)
#include<fstream>
#include<vector>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
vector<int> v;
int *h[100010];
void add(int x, int y)
{
if (h[x] == 0)
{
v.push_back(x);
h[x] = &v[v.size() - 1];
if (h[y] == 0)
h[y] = h[x];
else
*h[y] = *h[x];
}
else
{
if (h[y] == 0)
h[y] = h[x];
else
*h[y] = *h[x];
}
}
bool check(int x, int y)
{
if (h[y] == 0 || h[x] == 0)
return 0;
else if (*h[y] != *h[x])
return 0;
return 1;
}
int main()
{
int N,M;
in >> N >> M;
for (int i = 1; i <= M; ++i)
{
int op, x, y;
in >> op >> x >> y;
if (op == 1)
add(x, y);
else
{
if (check(x, y) == 0)
out << "NU\n";
else
out << "DA\n";
}
}
return 0;
}