Language: C++

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

int n, a[1000][1000];
vector<pii> es[1000][1000];
int h[1000][1000];

signed main(){
  cin >> n;
  rep(i, 0, n) rep(j, 0, n-1){
    cin >> a[i][j];
    a[i][j]--;
  }

  rep(i, 0, n) rep(j, 1, n-1){
    int u = i, v = a[i][j-1];
    if(u > v) swap(u, v);
    int x = i, y = a[i][j];
    if(x > y) swap(x, y);
    es[u][v].emplace_back(x, y);
    h[x][y]++;
  }

  stack<pii> st;
  rep(i, 0, n) rep(j, i+1, n){
    if(h[i][j] == 0) st.push({i, j});
  }

  vector<pii> ans;
  while(st.size()){
    int u = st.top().first, v = st.top().second;
    st.pop();
    ans.emplace_back(u, v);
    for(auto& e : es[u][v]){
      int x = e.first, y = e.second;
      h[x][y]--;
      if(h[x][y] == 0) st.push({x, y});
    }
  }

  if(sz(ans) == n*(n-1)/2){
    int tmp = 0;
    vvi used(n);
    for(auto& i : ans){
      int u = i.first, v = i.second;
      if(used[tmp][u] or used[tmp][v]){
        used.assign(n, false);
        tmp++;
      }
      used[tmp][u] = used[tmp][v] = true;
    }
    cout << tmp+1 << endl;
  }else{
    cout << -1 << endl;
  }

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:65:20: error: no matching function for call to 'std::vector<std::vector<long long int> >::assign(long long int&, bool)'
   65 |         used.assign(n, false);
      |         ~~~~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:828:9: note: candidate: 'template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  828 |         assign(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:828:9: note:   template argument deduction/substitution failed:
a.cc:65:20: note:   deduced conflicting types for parameter '_InputIterator' ('long long int' and 'bool')
   65 |         used.assign(n, false);
      |         ~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:808:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; size_type = long unsigned int; value_type = std::vector<long long int>]'
  808 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:808:47: note:   no known conversion for argument 2 from 'bool' to 'const std::vector<std::vector<long long int> >::value_type&' {aka 'const std::vector<long long int>&'}
  808 |       assign(size_type __n, const value_type& __val)
      |                             ~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_vector.h:855:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  855 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:855:7: note:   candidate expects 1 argument, 2 provided