Pagini recente » Borderou de evaluare (job #822092) | Cod sursa (job #225608) | Cod sursa (job #231991) | Cod sursa (job #1873210) | Cod sursa (job #1989012)
#include <bits/stdc++.h>
#define maxN 100010
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int multime[maxN];
int find(int x)
{
if(multime[x] == x)
return x;
return find(multime[x]);
}
void reunion(int x, int y)
{
multime[y] = x;
}
int main()
{
int n, m;
fin >> n >> m;
for(int i=1; i<=n; i++)
multime[i] = i;
while(m--)
{
int t, x, y;
fin >> t >> x >> y;
if(t==1)
reunion(find(x),find(y));
else
find(x) == find(y) ? fout << "DA\n" : fout << "NU\n";
}
return 0;
}