Language: C++

#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin>>n;
	vector<queue<ll> > que(n);
	map<pair<ll, ll> > pmap;
	rep(i, n)rep(j, n-1){
		ll temp; cin>>temp;
		que[i].push(temp-1);
	}

	ll match = 0, day = 0;
	ll loop = true;
	queue<pair<pair<ll, ll> ll> > Q;

	rep(i, n){
		ll opp = que[i].front(); que[i].pop();
		Q.push(mp(mp(i, opp), 1));
	}

	while(loop){
		loop = false;
		pair<pair<ll, ll> ll> p = Q.front(); Q.pop();
		ll m = (p.fi).fi;
		ll opp = (p.fi).se;
		ll d = p.se; day = d;
		ll a = min(m, opp);
		ll b = max(m, opp);
		pmap[mp(a, b)]++;
		if (pmap[mp(a, b)] == 2){
			loop = true;
			match++;
			if (q[a].size()){
				Q.push(mp(mp(a, q[a].front()), d+1));
				q[a].pop();
			}
			if (q[b].size()){
				Q.push(mp(mp(b, q[b].front()), d+1));
				q[b].pop();
			}
		}
	}

	if (match==n*(n-1)/2){
		cout << day << "\n";
	}else{
		cout << "-1\n";
	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:26: error: wrong number of template arguments (1, should be at least 2)
   31 |         map<pair<ll, ll> > pmap;
      |                          ^
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:102:11: note: provided for 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:9:17: error: 'long long' specified with 'std::pair<long long int, long long int>'
    9 | #define ll long long
      |                 ^~~~
a.cc:39:33: note: in expansion of macro 'll'
   39 |         queue<pair<pair<ll, ll> ll> > Q;
      |                                 ^~
a.cc:39:35: error: wrong number of template arguments (1, should be 2)
   39 |         queue<pair<pair<ll, ll> ll> > Q;
      |                                   ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:89:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
   89 |     struct pair;
      |            ^~~~
a.cc:39:37: error: template argument 1 is invalid
   39 |         queue<pair<pair<ll, ll> ll> > Q;
      |                                     ^
a.cc:39:37: error: template argument 2 is invalid
a.cc:43:19: error: request for member 'push' in 'Q', which is of non-class type 'int'
   43 |                 Q.push(mp(mp(i, opp), 1));
      |                   ^~~~
a.cc:9:17: error: 'long long' specified with 'std::pair<long long int, long long int>'
    9 | #define ll long long
      |                 ^~~~
a.cc:48:35: note: in expansion of macro 'll'
   48 |                 pair<pair<ll, ll> ll> p = Q.front(); Q.pop();
      |                                   ^~
a.cc:48:37: error: wrong number of template arguments (1, should be 2)
   48 |                 pair<pair<ll, ll> ll> p = Q.front(); Q.pop();
      |                                     ^
/usr/include/c++/14/bits/stl_pair.h:89:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
   89 |     struct pair;
      |            ^~~~
a.cc:48:45: error: request for member 'front' in 'Q', which is of non-class type 'int'
   48 |                 pair<pair<ll, ll> ll> p = Q.front(); Q.pop();
      |                                             ^~~~~
a.cc:48:56: error: request for member 'pop' in 'Q', which is of non-class type 'int'
   48 |                 pair<pair<ll, ll> ll> p = Q.front(); Q.pop();
      |                                                        ^~~
a.cc:17:12: error: request for member 'first' in 'p', which is of non-class type 'int'
   17 | #define fi first
      |            ^~~~~
a.cc:49:27: note: in expansion of macro 'fi'
   49 |                 ll m = (p.fi).fi;
      |                           ^~
a.cc:17:12: error: request for member 'first' in 'p', which is of non-class type 'int'
   17 | #define fi first
      |            ^~~~~
a.cc:50:29: note: in expansion of macro 'fi'
   50 |                 ll opp = (p.fi).se;
      |                             ^~
a.cc:18:12: error: request for member 'second' in 'p', which is of non-class type 'int'
   18 | #define se second
      |            ^~~~~~
a.cc:51:26: note: in expansion of macro 'se'
   51 |                 ll d = p.se; day = d;
      |                          ^~
a.cc:54:21: error: no match for 'operator[]' (operand types are 'int' and 'std::pair<long long int, long long int>')
   54 |                 pmap[mp(a, b)]++;
      |                     ^
a.cc:55:25: error: no match for 'operator[]' (operand types are 'int' and 'std::pair<long long int, long long int>')
   55 |                 if (pmap[mp(a, b)] == 2){
      |                         ^
a.cc:58:29: error: 'q' was not declared in this scope
   58 |                         if (q[a].size()){
      |                             ^
a.cc:59:35: error: request for member 'push' in 'Q', which is of non-class type 'int'
   59 |                                 Q.push(mp(mp(a, q[a].front()), d+1));
      |                                   ^~~~
a.cc:62:29: error: 'q' was not declared in this scope
   62 |                         if (q[b].size()){
      |                             ^
a.cc:63:35: error: request for member 'push' in 'Q', which is of non-class type 'int'
   63 |                                 Q.push(mp(mp(b, q[b].front()), d+1));
      |                                   ^~~~