Pagini recente » Cod sursa (job #199548) | Cod sursa (job #1372379) | Cod sursa (job #917064) | Cod sursa (job #1053652) | Cod sursa (job #2142353)
#include <fstream>
#include <cstdio>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
//freopen("disjoint.in", "r", stdin);
//freopen("disjoint.out", "w", stdout);
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;
}
char outBuffer[300000]; int p = -1;
int main()
{
int n, m, cod, x, y;
//scanf("%d %d", &n, &m);
fin >> n >> m;
while(m--)
{
//scanf("%d %d %d", &cod, &x, &y);
fin >> cod >> x >> 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;
}
}
}
fout << outBuffer;
}