Language: C++

        return ret;
    }

    int find(int u) {
      if(node[u] < 0) return u;
      int val = get_weight(node[u]);
      weight[u] += val;
      return node[u] = find(node[u]);
    }
};

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        UnionFind uf;
        for(int i=0; i<M; i++) {
            char c; cin >> c;
            if(c == '!') {
                int a, b, d; cin >> a >> b >> d;
                a--; b--;
                uf.unite(a, b, d);
            }
            else {
                int a, b; cin >> a >> b;
                a--; b--;
                if(uf.find(a) != uf.find(b)) cout << "UNKNOWN" << endl;
                else {
                    ll wa = uf.get_weight(a);
                    ll wb = uf.get_weight(b);
                    // printf("wa = %d, wb = %d\n", wa, wb);
                    cout << wb - wa << endl;
                }
            }
        }

        /*
        for(int i=0; i<N; i++) {
          printf("%d: parent = %d, weight = %lld, value = %lld\n", i, uf.node[i], uf.
weight[i], uf.get_weight(i));
        }
        */
    }
    return 0;
}

Compiler output:
a.cc:1:9: error: expected unqualified-id before 'return'
    1 |         return ret;
      |         ^~~~~~
a.cc:2:5: error: expected declaration before '}' token
    2 |     }
      |     ^
a.cc: In function 'int find(int)':
a.cc:5:10: error: 'node' was not declared in this scope
    5 |       if(node[u] < 0) return u;
      |          ^~~~
a.cc:6:28: error: 'node' was not declared in this scope
    6 |       int val = get_weight(node[u]);
      |                            ^~~~
a.cc:6:17: error: 'get_weight' was not declared in this scope
    6 |       int val = get_weight(node[u]);
      |                 ^~~~~~~~~~
a.cc:7:7: error: 'weight' was not declared in this scope
    7 |       weight[u] += val;
      |       ^~~~~~
a.cc: At global scope:
a.cc:10:1: error: expected declaration before '}' token
   10 | };
      | ^
a.cc: In function 'int main()':
a.cc:14:11: error: 'cin' was not declared in this scope
   14 |     while(cin >> N >> M, N) {
      |           ^~~
a.cc:15:9: error: 'UnionFind' was not declared in this scope
   15 |         UnionFind uf;
      |         ^~~~~~~~~
a.cc:21:17: error: 'uf' was not declared in this scope
   21 |                 uf.unite(a, b, d);
      |                 ^~
a.cc:26:20: error: 'uf' was not declared in this scope
   26 |                 if(uf.find(a) != uf.find(b)) cout << "UNKNOWN" << endl;
      |                    ^~
a.cc:26:46: error: 'cout' was not declared in this scope
   26 |                 if(uf.find(a) != uf.find(b)) cout << "UNKNOWN" << endl;
      |                                              ^~~~
a.cc:26:67: error: 'endl' was not declared in this scope
   26 |                 if(uf.find(a) != uf.find(b)) cout << "UNKNOWN" << endl;
      |                                                                   ^~~~
a.cc:28:21: error: 'll' was not declared in this scope
   28 |                     ll wa = uf.get_weight(a);
      |                     ^~
a.cc:29:23: error: expected ';' before 'wb'
   29 |                     ll wb = uf.get_weight(b);
      |                       ^~~
      |                       ;
a.cc:31:21: error: 'cout' was not declared in this scope
   31 |                     cout << wb - wa << endl;
      |                     ^~~~
a.cc:31:29: error: 'wb' was not declared in this scope; did you mean 'b'?
   31 |                     cout << wb - wa << endl;
      |                             ^~
      |                             b
a.cc:31:34: error: 'wa' was not declared in this scope; did you mean 'a'?
   31 |                     cout << wb - wa << endl;
      |                                  ^~
      |                                  a
a.cc:31:40: error: 'endl' was not declared in this scope
   31 |                     cout << wb - wa << endl;
      |                                        ^~~~