Pagini recente » Cod sursa (job #517982) | Cod sursa (job #618889) | Cod sursa (job #2529175) | Cod sursa (job #2879581) | Cod sursa (job #1646852)
#include <iostream>
#include <limits.h>
#include <cmath>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>
#include <map>
#include <fstream>
#include <list>
#include <queue>
#include <iomanip>
#include <deque>
#include <set>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.14159265
#define nmax 100001
#define inf (1<<30)
ifstream f("graf.in");
ofstream g("graf.out");
int tata[nmax];
int caut(int x)
{
int t;
for(t = x; tata[t] != t; t = tata[t])
for(int i = x; i != t;)
{
int a = tata[i];
tata[i] = t;
i = a;
}
return t;
}
void unesc(int x, int y)
{
int tx = caut(x);
int ty = caut(y);
tata[ty] = tx;
}
int query(int x, int y)
{
if(caut(x) == caut(y))
g<<"DA\n";
else
g<<"NU\n";
}
int main()
{
int n,m;
f >> n >> m;
for(int i = 1; i <=n; i++)
tata[i] = i;
for(int i = 1; i <= m; i++)
{
int t,x,y;
f >> t >> x >> y;
if (t == 1)
unesc(x,y);
else
query(x,y);
}
}