// Slower C++ solution:
#include <iostream>

#include <vector>

#include <utility>



template <std::size_t n>

class UnionFindTree

{

public:

    UnionFindTree()

    {

        for (std::size_t i = 0; i < n; i++) {

            parent[i] = i;

            rank[i] = 0;

            size[i] = 1;

        }

    }



    bool same(const std::size_t a, const std::size_t b)

    {

        return find(a) == find(b);

    }



    std::size_t find(const std::size_t a)

    {

        if (parent[a] == a) {

            return a;

        } else {

            return parent[a] = find(parent[a]);

        }

    }



    void unite(const std::size_t a_, const std::size_t b_)

    {

        const std::size_t a = find(a_);

        const std::size_t b = find(b_);

        if (a == b) {

            return;

        }

        if (rank[a] > rank[b]) {

            parent[b] = a;

            size[a] += size[b];

        } else {

            parent[a] = b;

            size[b] += size[a];

        }

        if (rank[a] == rank[b]) {

            rank[b]++;

        }

    }



    std::size_t getSize(const std::size_t a)

    {

        return size[a];

    }



private:

    std::size_t parent[n];

    std::size_t rank[n];

    std::size_t size[n];

};



template <std::size_t m, std::size_t n = m>

class UnionFindTree2D

{

public:

    UnionFindTree2D()

    {

        for (std::size_t i = 0; i < m; i++) {

            for (std::size_t j = 0; j < n; j++) {

                parent[i][j] = std::make_pair(i, j);

                rank[i][j] = 0;

                size[i][j] = 1;

            }

        }

    }



    bool same(const std::pair<std::size_t, std::size_t>& a, const std::pair<std::size_t, std::size_t>& b)

    {

        return find(a) == find(b);

    }



    std::pair<std::size_t, std::size_t> find(const std::pair<std::size_t, std::size_t>& a)

    {

        if (parent[a.first][a.second] == a) {

            return a;

        } else {

            return parent[a.first][a.second] = find(parent[a.first][a.second]);

        }

    }



    void unite(const std::pair<std::size_t, std::size_t>& a_, const std::pair<std::size_t, std::size_t>& b_)

    {

        const std::pair<std::size_t, std::size_t>& a = find(a_);

        const std::pair<std::size_t, std::size_t>& b = find(b_);

        if (a == b) {

            return;

        }

        if (rank[a.first][a.second] > rank[b.first][b.second]) {

            parent[b.first][b.second] = a;

            size[a.first][a.second] += size[b.first][b.second];

        } else {

            parent[a.first][a.second] = b;

            size[b.first][b.second] += size[a.first][a.second];

        }

        if (rank[a.first][a.second] == rank[b.first][b.second]) {

            rank[b.first][b.second]++;

        }

    }



    std::size_t getSize(const std::pair<std::size_t, std::size_t>& a)

    {

        return size[a.first][a.second];

    }



private:

    std::pair<std::size_t, std::size_t> parent[m][n];

    std::size_t rank[m][n];

    std::size_t size[m][n];

};



using namespace std;



int main()

{

    constexpr std::size_t NUM = 10000;

    UnionFindTree<NUM> u;

    std::size_t n, q;

    cin >> n >> q;

    for (std::size_t i = 0; i < q; i++) {

        char c;

        cin >> c;

        if (c == '0') {

            int x, y;

            cin >> x >> y;

            u.unite(x, y);

        } else if (c == '1') {

            int x, y;

            cin >> x >> y;

            cout << (u.same(x, y) ? 1 : 0) << endl;

        } else {

            cerr << "Piyo" << endl;

        }

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.232988465183998x):
#include <iostream>

#include <type_traits>

#include <vector>

#include <cstdint>

#include <cassert>

#include <numeric>

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_1_A"



using i32   = int32_t;

using i64   = int64_t;

using u32   = uint32_t;

using u64   = uint64_t;

using uint  = unsigned int;

using usize = std::size_t;

using ll    = long long;

using ull   = unsigned long long;

using ld    = long double;

template<typename T, usize n>

using arr = T (&)[n];

template<typename T, usize n>

using c_arr = const T (&)[n];

template<typename T>

T in()

{

    T v;

    return std::cin >> v, v;

}

template<typename T, typename Uint, usize n, usize i>

T in_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type) { return in<T>(); }

template<typename T, typename Uint, usize n, usize i>

auto in_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type& szs)

{

    const usize s = (usize)szs[i];

    std::vector<decltype(in_v<T, Uint, n, i + 1>(szs))> ans(s);

    for (usize j = 0; j < s; j++) { ans[j] = in_v<T, Uint, n, i + 1>(szs); }

    return ans;

}

template<typename T, typename Uint, usize n>

auto in_v(c_arr<Uint, n> szs) { return in_v<T, Uint, n, 0>(szs); }

template<typename... Types>

auto in_t() { return std::tuple<std::decay_t<Types>...>{in<Types>()...}; }



template<typename T>

void out(const T& v) { std::cout << v; }

template<typename T>

void out(const std::vector<T>& v)

{

    for (usize i = 0; i < v.size(); i++) {

        if (i > 0) { std::cout << ' '; }

        out(v[i]);

    }

    std::cout << "\n";

}

template<typename T1, typename T2>

void out(const std::pair<T1, T2>& v) { out(v.first), std::cout << ' ', out(v.second); }

template<typename T, typename... Args>

void out(const T& v, const Args... args) { out(v), std::cout << ' ', out(args...); }

template<typename... Args>

void outln(const Args... args) { out(args...), std::cout << '\n'; }

template<typename... Args>

void outel(const Args... args) { out(args...), std::cout << std::endl; }



class unionfind

{

public:

    unionfind(const usize sz) : sz{sz}, rt(sz), comp_sz(sz, 1) { std::iota(rt.begin(), rt.end(), 0); }

    usize root_of(const usize a) { return assert(a < sz), rt[a] == a ? a : rt[a] = root_of(rt[a]); }

    bool unite(usize a, usize b)

    {

        assert(a < sz), assert(b < sz), a = root_of(a), b = root_of(b);

        if (a == b) { return false; }

        if (comp_sz[a] < comp_sz[b]) { std::swap(a, b); }

        return comp_sz[a] += comp_sz[b], rt[b] = a, true;

    }

    usize size_of(const usize a) { return assert(a < sz), comp_sz[root_of(a)]; }

    friend std::ostream& operator<<(std::ostream& os, const unionfind& uf)

    {

        os << "[";

        for (usize i = 0; i < uf.sz; i++) { os << uf.rt[i] << (i + 1 == uf.sz ? "" : ","); }

        return (os << "]\n");

    }



private:

    const usize sz;

    std::vector<usize> rt, comp_sz;

};

int main()

{

    const auto n = in<usize>();

    const auto q = in<usize>();

    unionfind uf(n);

    for (usize i = 0; i < q; i++) {

        const auto c = in<usize>();

        const auto u = in<usize>() ;

        const auto v = in<usize>() ;

        if (c == 0) {

            uf.unite(u, v);

        } else {

            outln(uf.root_of(u) == uf.root_of(v));

        }

    }

    return 0;

}