Pagini recente » Cod sursa (job #673425) | Cod sursa (job #893149) | Cod sursa (job #2402131) | Cod sursa (job #3194717) | Cod sursa (job #2499480)
// FFF.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
//#include "pch.h"
#include <iostream>
#include <fstream>
#include <vector>
#define NMAX 50001
using namespace std;
int n, q;
vector<int> v;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int main()
{
fin >> n >> q;
for (int i = 0; i < n; i++)v.push_back(i);
for (int i = 0; i < q; i++)
{
int c;
fin >> c;
int x, y;
fin >> x >> y;
x--; y--;
switch (c)
{
case 1:
if (v[x] > v[y])
{
int aux = x;
x = y;
y = aux;
}
for (int j = 0; j < n; j++) if (j != x && j != y && v[j] == v[y]) v[j] = v[x];
v[y] = v[x];
break;
case 2:
if (v[x] == v[y]) fout << "DA\n";
else fout << "NU\n";
break;
}
}
return 0;
}