Pagini recente » Cod sursa (job #2571048) | Monitorul de evaluare | Cod sursa (job #2897085) | Cod sursa (job #2721241) | Cod sursa (job #2142361)
#include <fstream>
#include <cstdio>
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;
}
char outBuffer[300000]; int p = -1;
int main()
{
//freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
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;
}
}
}
puts(outBuffer);
}