Pagini recente » Istoria paginii runda/ioi_training | Profil M@2Te4i | Istoria paginii utilizator/lavismile | Cod sursa (job #577040) | Cod sursa (job #2142340)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[100001];
int root(int x)
{
int y = x, next;
while(t[y])
{
y = t[y];
}
while(t[x])
{
next = t[x];
t[x] = y;
x = next;
}
return y;
}
#define SIZE 200000
__attribute__((always_inline)) void read(int &num)
{
static char inBuffer[SIZE];
static int p = ~-SIZE; num = 0x0;
while(inBuffer[p] < 0x30 | inBuffer[p] > 0x39)
{
++p != SIZE || (fread(inBuffer, 0x1, SIZE, stdin), p = 0x0);
}
while(inBuffer[p] > 0x2F & inBuffer[p] < 0x3A)
{
num = num * 0xA + inBuffer[p] - 0x30;
++p != SIZE || (fread(inBuffer, 0x1, SIZE, stdin), p = 0x0);
}
}
int main()
{
int n, m, cod, x, y;
read(n); read(m);
while(m--)
{
read(cod); read(x); read(y);
if(cod & 1)
{
t[root(x)] = root(y);
}
else
{
if (root(x) ^ root(y)) fout << "NU\n";
else fout << "DA\n";
}
}
}