Pagini recente » Istoria paginii runda/concurs_epic/clasament | Cod sursa (job #2393266) | Cod sursa (job #930323) | Cod sursa (job #2707905) | Cod sursa (job #2142413)
#include <fstream>
#include <cstdio>
using namespace std;
//ifstream fin("disjoint.in");
int t[100001];
__attribute__((always_inline)) 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);
}
}
char outBuffer[300000]; int p = -1;
int main()
{
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
int n, m, cod, x, y;
//fin >> n >> m;
read(n); read(m);
while(m--)
{
//fin >> cod >> x >> y;
read(cod); read(x); read(y);
if(cod & 1)
{
t[root(x)] = root(y);
}
else
{
if(root(x) ^ root(y))
{
outBuffer[++p] = 78;
outBuffer[++p] = 85;
outBuffer[++p] = 10;
}
else
{
outBuffer[++p] = 68;
outBuffer[++p] = 65;
outBuffer[++p] = 10;
}
}
}
puts(outBuffer);
}