/BCDAISY - Chú bò hư hỏng

<Problem>

https://www.spoj.com/PTIT/problems/BCDAISY/
              #include <iostream>
        using namespace std;
         
        int findRoot(int n, int* root) {
          if (root[n] != n) root[n] = findRoot(root[n], root);
          return root[n];
        }
         
        int main() {
          int n, m;
          cin >> n >> m;
         
          int* root = new int[n + 1];
         
          for (int i = 1; i <= n; i++) {
            root[i] = i;
          }
         
          for (int i = 0; i < m; i++) {
            int a, b;
            cin >> a >> b;
         
            int rootA = findRoot(a, root);
            int rootB = findRoot(b, root);
            // union
            if (rootA != rootB) {
              if (rootA < rootB) {
                root[rootB] = rootA;
              }
              else root[rootA] = rootB;
            }
          }
         
          for (int i = 1; i <= n; i++) {
            if (root[i] != 1) {
              cout << i << endl;
            }
          }
         
          return 0;
        }