Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;

vector<bool> seen, visited;

void dfs(const Graph &G, int v, vi &order, bool &able) {
  seen[v] = true;

  for (auto nv : G[v]) {
    if (seen[nv] && !visited[nv]) {
      able = false;
      return;
    }
    if (!seen[nv]) dfs(G, nv, order, able);

    if (!able) return;
  }

  order.push_back(v);
  visited[v] = true;
}

void solve() {
  int n; cin >> n;
  const int sz = n*(n-1)/2;

  Graph G(sz);
  vi start, finish;
  int prev, next;  // game number
  int tmp;
  vi sum(n, 0);

  rep(i,n) {
    cin >> tmp; --tmp;

    prev = sum[min(i,tmp)] + abs(i-tmp) - 1;
    start.push_back(prev);

    rep(j,n-2) {
      cin >> tmp; --tmp;

      next = sum[min(i,tmp)] + abs(i-tmp) - 1;
      G[prev].push_back(next);
      prev = next;
    }

    finish.push_back(next);
    sum[i+1] = sum[i] + (n-1)-i;
  }

  seen.assign(sz, false);
  visited.assign(sz, false);
  vi order;
  bool able = true;
  rep(i,n) {
    if (seen[start[i]]) continue;
    dfs(G, start[i], order, able);
    if (!able) {
      cout << -1 << endl;
      return;
    }
  }
  reverse(ALL(order));

  vi days(sz, 1);
  for (auto v : order) {
    for (auto nv : G[v]) {
      days[nv] = max(days[nv], days[v]+1);
    }
  }

  int ans = 0;
  rep(i,n) ans = max(days[finish[i]]);
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:82:21: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   82 |   rep(i,n) ans = max(days[finish[i]]);
      |                  ~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
a.cc:82:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   82 |   rep(i,n) ans = max(days[finish[i]]);
      |                  ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided