/BCBIN - Các thùng nước

<Problem>

https://www.spoj.com/PTIT/problems/BCBIN/
              #include <iostream>
        using namespace std;
        
        #define SIZE 100000
        int* root = new int[SIZE + 1];
        
        // ý tưởng là tạo ra cây khung chung gốc bằng cách tạo ra gốc và cập nhật lại gốc
        // và các gốc cũ sẽ kết nối với gốc mới -> tạo thành một cây khung với 1 gốc chính và các gốc phụ
        
        int findRoot(int n) {
          if (root[n] != n) root[n] = findRoot(root[n]);
          return root[n];
        }
        
        int main() {
          int n;
          cin >> n;
        
          for (int i = 1; i <= SIZE; i++) {
            root[i] = i;
          }
        
          for (int i = 1; i <= n; i++) {
            int a, b, t;
            cin >> a >> b >> t;
        
            int rootA = findRoot(a);
            int rootB = findRoot(b);
        
            //cout << rootA << " " << rootB << endl;
        
            if (t == 1) {
              if (rootA != rootB) root[rootA] = rootB;
            }
            else {
              if (rootA == rootB) {
                cout << "1" << endl;
              }
              else cout << "0" << endl;
            }
          }
          return 0;
        }