#include <stdio.h>
#include <stdlib.h>

typedef struct _tree_element tree_elm;
struct _tree_element {
    int value;
    tree_elm *left;
    tree_elm *right;
};

void union_tree(tree_elm **t_p, tree_elm *t1, tree_elm *t2);
void insert_tree_element(tree_elm *t, tree_elm *t2);

void union_tree(tree_elm **t_p, tree_elm *t1, tree_elm *t2) {
    if (t1 == t2) return;
    if (t1->left != NULL) {
        union_tree(t_p, t1->left, t2);
        t1->left = NULL;
    }
    if (t1->right !=NULL) {
        union_tree(t_p, t1->right, t2);
        t1->right = NULL;
    }
    insert_tree_element(t1, t2);
    t_p[t1->value] = t2;
}

void insert_tree_element(tree_elm *t, tree_elm *t2) {
    while (t != NULL) {
        if (t->value < t2->value) {
            if (t2->left == NULL) {
                t2->left = t;
                return;
            }
            else { // all values are distinct
                t2 = t2->left;
            }
        }
        else {
            if (t2->right == NULL) {
                t2->right = t;
                return;
            }
            else {
                t2 = t2->right;
            }
        }
    }
}


int elm_in_tree(const int value, tree_elm *t) {
    while (t != NULL) {
        if (t->value == value) {
            return 1;
        }
        else if (value < t->value) {
            t = t->left;
        }
        else {
            t = t->right;
        }
    }
    return 0;
}

int main(void) {
    int n, q, op, x, y, i;
    tree_elm *t_elm;
    tree_elm *t_elms;
    tree_elm **t;
    scanf("%d %d", &n, &q);
    t_elms = (tree_elm *)malloc(sizeof(tree_elm) * n);
    t = (tree_elm **)malloc(sizeof(tree_elm *) * n);
    for (i = 0; i < n; i++) {
        t_elm = &(t_elms[i]);
        t_elm->value = i;
        t_elm->left = NULL;
        t_elm->right = NULL;
        t[i] = t_elm;
    }
    while (q--) {
        scanf("%d %d %d", &op, &x, &y);
        if (op == 0) {
            union_tree(t, t[x], t[y]);
        }
        else { // op == 1
            printf("%d\n", elm_in_tree(x, t[y]));
        }
    }

    free(t);
    free(t_elms);

    return 0;
}