Language: C++

        // cout << "memo[" << match << "]: " << memo[match] << endl;
        return count;
    }

    int max = count;
    for (int i = 0; i < (int) depends.size(); i++) {
        visited.insert(match);
        int res = solve(depends[i], count + 1, visited);
        visited.erase(match);
        if (res < 0) {
            max = res;
            break;
        } else if (res > max) {
            max = res;
        }
    }

    memo[match] = max;
    // cout << "memo[" << match << "]: " << memo[match] << endl;

    return max;
}

#define MATCH(p1, p2, n) (((p1) - 1) * (n) + ((p2) - 1))

int main(void) {
    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - 1; j++) {
            int x;
            cin >> x;
            edges[i].push_back(x);
        }
    }

    for (int i = 0; i < n; i++) {
        int prev_match = -1;
        for (int j = 0; j < n - 1; j++) {
            int p1 = i + 1;
            int p2 = edges[i][j];

            int cur_match = MATCH(p1, p2, n);

            if (prev_match >= 0) {
                dependencies[cur_match].push_back(prev_match);
            }

            // search from opposite edges
            int k;
            for (k = n - 1; k >= 0; k--) {
                if (edges[p2 - 1][k] == p1) {
                    break;
                }
            }
            if (k > 0) {
                int match = MATCH(p2, edges[p2 - 1][k - 1], n);
                dependencies[cur_match].push_back(match);
            }

            prev_match = cur_match;
        }
    }

    // to debug dependencies
    // for (int i = 0; i < DEP_SIZE(n); i++) {
    //     cout << "dependency for " << i << ": ";
    //     for (int j = 0; j < (int) dependencies[i].size(); j++) {
    //         cout << dependencies[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    set<int> s;
    int ans = 0;
    for (int i = 0; i < DEP_SIZE(n); i++) {
        s.clear();
        int res = solve(i, 1, s);
        if (res < 0) {
            ans = -1;
            break;
        } else if (res > ans) {
            ans = res;
        }
    }

    cout << ans << endl;
    
    return 0;
}


Compiler output:
a.cc:2:9: error: expected unqualified-id before 'return'
    2 |         return count;
      |         ^~~~~~
a.cc:3:5: error: expected declaration before '}' token
    3 |     }
      |     ^
a.cc:5:15: error: 'count' was not declared in this scope
    5 |     int max = count;
      |               ^~~~~
a.cc:6:5: error: expected unqualified-id before 'for'
    6 |     for (int i = 0; i < (int) depends.size(); i++) {
      |     ^~~
a.cc:6:21: error: 'i' does not name a type
    6 |     for (int i = 0; i < (int) depends.size(); i++) {
      |                     ^
a.cc:6:47: error: 'i' does not name a type
    6 |     for (int i = 0; i < (int) depends.size(); i++) {
      |                                               ^
a.cc:18:5: error: 'memo' does not name a type
   18 |     memo[match] = max;
      |     ^~~~
a.cc:21:5: error: expected unqualified-id before 'return'
   21 |     return max;
      |     ^~~~~~
a.cc:22:1: error: expected declaration before '}' token
   22 | }
      | ^
a.cc: In function 'int main()':
a.cc:27:5: error: 'cin' was not declared in this scope
   27 |     cin >> n;
      |     ^~~
a.cc:27:12: error: 'n' was not declared in this scope
   27 |     cin >> n;
      |            ^
a.cc:33:13: error: 'edges' was not declared in this scope
   33 |             edges[i].push_back(x);
      |             ^~~~~
a.cc:41:22: error: 'edges' was not declared in this scope
   41 |             int p2 = edges[i][j];
      |                      ^~~~~
a.cc:46:17: error: 'dependencies' was not declared in this scope
   46 |                 dependencies[cur_match].push_back(prev_match);
      |                 ^~~~~~~~~~~~
a.cc:58:17: error: 'dependencies' was not declared in this scope
   58 |                 dependencies[cur_match].push_back(match);
      |                 ^~~~~~~~~~~~
a.cc:74:5: error: 'set' was not declared in this scope
   74 |     set<int> s;
      |     ^~~
a.cc:74:9: error: expected primary-expression before 'int'
   74 |     set<int> s;
      |         ^~~
a.cc:76:25: error: 'DEP_SIZE' was not declared in this scope
   76 |     for (int i = 0; i < DEP_SIZE(n); i++) {
      |                         ^~~~~~~~
a.cc:77:9: error: 's' was not declared in this scope
   77 |         s.clear();
      |         ^
a.cc:78:19: error: 'solve' was not declared in this scope
   78 |         int res = solve(i, 1, s);
      |                   ^~~~~
a.cc:87:5: error: 'cout' was not declared in this scope
   87 |     cout << ans << endl;
      |     ^~~~
a.cc:87:20: error: 'endl' was not declared in this scope
   87 |     cout << ans << endl;
      |                    ^~~~