Cod sursa(job #2561546)

Utilizator matthriscuMatt . matthriscu Data 28 februarie 2020 22:00:57
Problema Paduri de multimi disjuncte Scor 40
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <stdio.h>

int main() {
    int n, m, v[100005], i, q, x, y, j, t;
    freopen("disjoint.in", "r", stdin);
    freopen("disjoint.out", "w", stdout);
    scanf("%d%d", &n, &m);
    for(i = 1; i <= n; ++i)
        v[i] = i;
    for(i = 1; i <= m; ++i) {
        scanf("%d%d%d", &q, &x, &y);
        if(q == 1) {
            t = v[y];
            for(j = 1; j <= n; ++j) {
                if(v[j] == t)
                    v[j] = v[x];
            }
        }
        else
            if(v[x] == v[y])
                printf("DA\n");
            else
                printf("NU\n");
    }
}