Language: C++

template<class D>
struct Hungarian {
    V<D> le, ri;
    V<int> perm;

    Hungarian(const VV<D> &c) {
        int n = int(c.size()), m = int(c[0].size());
        assert(n <= m);
        le = V<D>(n, D(0)); ri = V<D>(m, D(0));
        perm = V<int>(n);
        V<int> to_r(n, -1), to_l(m, -1);

        for (int s = 0; s < n; s++) {
            V<bool> l_u(n), r_u(m); l_u[s] = true;
            V<int> tr(m, -1), min_l(m, s);
            V<D> min_cost(m);
            for (int j = 0; j < m; j++) min_cost[j] = c[s][j] + le[s] + ri[j];
            while (true) {
                int r = -1;
                D d = numeric_limits<D>::max();
                for (int j = 0; j < m; j++) {
                    if (!r_u[j] && min_cost[j] < d) {
                        r = j;
                        d = min_cost[j];
                    }
                }
                for (int i = 0; i < n; i++) if (l_u[i]) le[i] -= d;
                for (int j = 0; j < m; j++) {
                    if (r_u[j]) ri[j] += d;
                    else min_cost[j] -= d;
                }
                tr[r] = min_l[r];
                int l = to_l[r];
                if (l == -1) {
                    while (r != -1) {
                        int nl = tr[r], nr = to_r[nl];
                        to_l[r] = nl; to_r[nl] = r;
                        r = nr;
                    }
                    break;
                }
                l_u[l] = r_u[r] = true;
                for (int j = 0; j < m; j++) {
                    D cost = c[l][j] + le[l] + ri[j];
                    if (cost < min_cost[j]) {
                        min_l[j] = l;
                        min_cost[j] = cost;
                    }
                }
            }
        }
        perm = to_r;
    }
};



Compiler output:
a.cc:3:5: error: 'V' does not name a type
    3 |     V<D> le, ri;
      |     ^
a.cc:4:5: error: 'V' does not name a type
    4 |     V<int> perm;
      |     ^
a.cc:6:21: error: 'VV' does not name a type
    6 |     Hungarian(const VV<D> &c) {
      |                     ^~
a.cc:6:23: error: expected ',' or '...' before '<' token
    6 |     Hungarian(const VV<D> &c) {
      |                       ^
a.cc: In constructor 'Hungarian<D>::Hungarian(int)':
a.cc:7:21: error: 'c' was not declared in this scope
    7 |         int n = int(c.size()), m = int(c[0].size());
      |                     ^
a.cc:8:9: error: there are no arguments to 'assert' that depend on a template parameter, so a declaration of 'assert' must be available [-fpermissive]
    8 |         assert(n <= m);
      |         ^~~~~~
a.cc:8:9: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:9:9: error: 'le' was not declared in this scope
    9 |         le = V<D>(n, D(0)); ri = V<D>(m, D(0));
      |         ^~
a.cc:9:14: error: 'V' was not declared in this scope
    9 |         le = V<D>(n, D(0)); ri = V<D>(m, D(0));
      |              ^
a.cc:9:17: error: expected primary-expression before '>' token
    9 |         le = V<D>(n, D(0)); ri = V<D>(m, D(0));
      |                 ^
a.cc:9:29: error: 'ri' was not declared in this scope
    9 |         le = V<D>(n, D(0)); ri = V<D>(m, D(0));
      |                             ^~
a.cc:9:37: error: expected primary-expression before '>' token
    9 |         le = V<D>(n, D(0)); ri = V<D>(m, D(0));
      |                                     ^
a.cc:10:9: error: 'perm' was not declared in this scope
   10 |         perm = V<int>(n);
      |         ^~~~
a.cc:10:18: error: expected primary-expression before 'int'
   10 |         perm = V<int>(n);
      |                  ^~~
a.cc:11:11: error: expected primary-expression before 'int'
   11 |         V<int> to_r(n, -1), to_l(m, -1);
      |           ^~~
a.cc:14:15: error: expected primary-expression before 'bool'
   14 |             V<bool> l_u(n), r_u(m); l_u[s] = true;
      |               ^~~~
a.cc:14:37: error: 'l_u' was not declared in this scope
   14 |             V<bool> l_u(n), r_u(m); l_u[s] = true;
      |                                     ^~~
a.cc:15:15: error: expected primary-expression before 'int'
   15 |             V<int> tr(m, -1), min_l(m, s);
      |               ^~~
a.cc:16:16: error: expected primary-expression before '>' token
   16 |             V<D> min_cost(m);
      |                ^
a.cc:16:18: error: there are no arguments to 'min_cost' that depend on a template parameter, so a declaration of 'min_cost' must be available [-fpermissive]
   16 |             V<D> min_cost(m);
      |                  ^~~~~~~~
a.cc:17:41: error: 'min_cost' was not declared in this scope
   17 |             for (int j = 0; j < m; j++) min_cost[j] = c[s][j] + le[s] + ri[j];
      |                                         ^~~~~~~~
a.cc:20:23: error: 'numeric_limits' was not declared in this scope
   20 |                 D d = numeric_limits<D>::max();
      |                       ^~~~~~~~~~~~~~
a.cc:20:39: error: expected primary-expression before '>' token
   20 |                 D d = numeric_limits<D>::max();
      |                                       ^
a.cc:20:42: error: '::max' has not been declared
   20 |                 D d = numeric_limits<D>::max();
      |                                          ^~~
a.cc:22:26: error: 'r_u' was not declared in this scope
   22 |                     if (!r_u[j] && min_cost[j] < d) {
      |                          ^~~
a.cc:22:36: error: 'min_cost' was not declared in this scope
   22 |                     if (!r_u[j] && min_cost[j] < d) {
      |                                    ^~~~~~~~
a.cc:29:25: error: 'r_u' was not declared in this scope
   29 |                     if (r_u[j]) ri[j] += d;
      |                         ^~~
a.cc:30:26: error: 'min_cost' was not declared in this scope
   30 |                     else min_cost[j] -= d;
      |                          ^~~~~~~~
a.cc:32:17: error: 'tr' was not declared in this scope; did you mean 'r'?
   32 |                 tr[r] = min_l[r];
      |                 ^~
      |                 r
a.cc:32:25: error: 'min_l' was not declared in this scope
   32 |                 tr[r] = min_l[r];
      |                         ^~~~~
a.cc:33:25: error: 'to_l' was not declared in this scope
   33 |                 int l = to_l[r];
      |                         ^~~~
a.cc:37:39: error: 'to_r' was not declared in this scope
   37 |                         to_l[r] = nl; to_r[nl] = r;
      |                                       ^~~~
a.cc:38:29: error: 'nr' was not declared in this scope; did you mean 'nl'?
   38 |                         r = nr;
      |                             ^~
      |                             nl
a.cc:42:26: error: 'r_u' was not declared in this scope
   42 |                 l_u[l] = r_u[r] = true;
      |                          ^~~
a.cc:45:32: error: 'min_cost' was not declared in this scope
   45 |                     if (cost < min_cost[j]) {
      |                                ^~~~~~~~
a.cc:52:16: error: 'to_r' was not declared in this scope
   52 |         perm = to_r;
      |                ^~~~