Pagini recente » Cod sursa (job #2973700) | Clasament ghhhh | Cod sursa (job #2910662) | Cod sursa (job #3224082) | Cod sursa (job #1670952)
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <map>
#define pb push_back
#define mp make_pair
#define INF numeric_limits<int>::max()
#define lsb(x) (-x)&x
#define int64 long long
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int g[100001],n,m;
int group(int x)
{
if(g[x]==x)return x;
g[x]=group(g[x]);
return g[x];
}
void unite(int x,int y)
{
g[group(x)]=group(y);
}
int main()
{
in>>n>>m;
for(int i=1;i<=n;i++)
g[i]=i;
for(;m;m--)
{
int t,x,y;
in>>t>>x>>y;
if(t==1)
unite(x,y);
else
out<<(group(x)==group(y) ? "DA\n" : "NU\n");
}
return 0;
}