Cod sursa(job #505003)
| Utilizator | Data | 29 noiembrie 2010 21:33:27 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <stdio.h>
using namespace std;
#define nmax 100005
int GR[nmax];
int grupa ( int x )
{
if (GR[x] == x) return x;
return grupa(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;
}
