Pagini recente » Cod sursa (job #1747733) | Cod sursa (job #1491574) | Cod sursa (job #1714055) | Cod sursa (job #286921) | Cod sursa (job #505005)
Cod sursa(job #505005)
#include <stdio.h>
using namespace std;
#define nmax 100005
int GR[nmax];
int grupa ( int x )
{
if (GR[x] == x) return x;
GR[x] = grupa(GR[x])
return GR[x];
}
int main ()
{
int n, t, tip, x, y;
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d %d ", &n, &t);
while ( t-- )
{
scanf("%d %d %d ", &tip, &x, &y);
if ( tip == 1 )
GR[grupa(x)] = grupa(y);
else
if (GR[x] == GR[y]) printf("DA\n");
else printf("NU\n");
}
return 0;
}