Pagini recente » Cod sursa (job #2927703) | Cod sursa (job #2782645) | Cod sursa (job #96337) | Cod sursa (job #2074422) | Cod sursa (job #1376949)
/*
Those without power, seek us!
Those with power, fear us!
We are the Order of the Black Knights!
*/
#include<fstream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<ctime>
#include<bitset>
#include<cmath>
#include<iomanip>
#include<set>
#define f cin
#define g cout
#include<queue>
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned int
#define mod 1000000009LL
#define SQR 350
#define inf 1<<30
#define div fdasfasd
#define hash dsafdsfds
#define od 100003
#define mod 1999999973LL
#define DIM 60010000
#define base 256
#define bas 255
#define N 100100
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
/*
int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};
*/
int n,m,T[N],t,x,y,R[N];
int find(int x)
{
int aux=x;
while(x!=T[x])
x=T[x];
int tata=x;
x=aux;
while(x!=tata)
{
aux=T[x];
T[x]=tata;
x=aux;
}
return tata;
}
void unite(int x,int y)
{
if(R[x]>R[y])
swap(x,y);
if(R[x]==R[y])
R[x]++;
T[y]=x;
}
int main ()
{
f>>n>>m;
FOR(i,1,n)
T[i]=i;
FOR(i,1,m)
{
f>>t;
if(t==1)
{
f>>x>>y;
x=find(x);
y=find(y);
if(x!=y)
unite(x,y);
}
else
{
f>>x>>y;
x=find(x);
y=find(y);
if(x==y)
g<<"DA\n";
else
g<<"NU\n";
}
}
return 0;
}