Language: C++

v#include<bits/stdc++.h>
using namespace std;
int max_v = 0;
map<pair<int,int>,int>uniq;
int get_idx(pair<int,int>p){
    if(uniq.find(p) == uniq.end()){
        uniq[p] = max_v++;
    }
    return uniq[p];
}
vector<vector<int>>edge;
void dfs(vector<int>&d,int v,int value){
    for(auto nxt : edge[v]){
        if(d[nxt] < value + 1){
            d[nxt] = value + 1;
            dfs(d,nxt,d[nxt]);
        }
    }
    return;
}
signed main(){
    int N; cin >> N;
    vector<vector<int>>g(N);
    for(auto& v : g){
        for(int i = 0; i < N - 1; ++i){
            int t; cin >> t;
            v.push_back(--t);
        }
    }
    // 0-index
    vector<vector<int>>pos(N,vector<int>(N,-1LL));
    for(int i = 0; i < g.size(); ++i){
        for(int j = 0; j < g[i].size(); ++j){
            auto e = g[i][j];
            pos[i][e] = j;
        }
    }
    vector<vector<bool>>used(N,vector<bool>(N-1,false));
    edge.resize(N*N);
    vector<int>d(N*N,-1);
    vector<int>in(N*N);
    auto f = [](int i, int j){
        return make_pair(min(i,j), max(i,j));
    };
    for(int j = 0; j < N - 1; ++j){
        for(int i = 0; i < N; ++i){
            if(used[i][j])continue;
            //cout <<  i + 1 << " " << g[i][j]+ 1 << endl;
            auto e = g[i][j];
            int rj = pos[e][i];
            auto p = f(i,e);
            if(j + 1  < N - 1){
                auto nxt = f(i,g[i][j + 1]);
                in[get_idx(nxt)]++;
                edge[get_idx(p)].push_back(get_idx(nxt));
            }
            if(rj + 1 < N - 1 ){
                auto nxt = f(e,rj + 1);
                in[get_idx(nxt)]++;
                edge[get_idx(p)].push_back(get_idx(nxt));
            }
            used[i][j] = used[e][rj] = true;
        }
    }
    bool valid = false;
    for(int p = 0; p < max_v; ++p){
        if(in[p])continue;
        valid = true;
        if(d[p]  == -1)
            dfs(d,p,1LL);
        
    }
    if(not valid) return puts("-1") * 0;
    cout << *max_element(d.begin(), d.end()) << endl;
}


Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | v#include<bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'v' does not name a type
    1 | v#include<bits/stdc++.h>
      | ^
a.cc:4:1: error: 'map' does not name a type
    4 | map<pair<int,int>,int>uniq;
      | ^~~
a.cc:5:13: error: 'pair' was not declared in this scope
    5 | int get_idx(pair<int,int>p){
      |             ^~~~
a.cc:5:18: error: expected primary-expression before 'int'
    5 | int get_idx(pair<int,int>p){
      |                  ^~~
a.cc:5:22: error: expected primary-expression before 'int'
    5 | int get_idx(pair<int,int>p){
      |                      ^~~
a.cc:5:27: error: expression list treated as compound expression in initializer [-fpermissive]
    5 | int get_idx(pair<int,int>p){
      |                           ^
a.cc:11:1: error: 'vector' does not name a type
   11 | vector<vector<int>>edge;
      | ^~~~~~
a.cc:12:6: error: variable or field 'dfs' declared void
   12 | void dfs(vector<int>&d,int v,int value){
      |      ^~~
a.cc:12:10: error: 'vector' was not declared in this scope
   12 | void dfs(vector<int>&d,int v,int value){
      |          ^~~~~~
a.cc:12:17: error: expected primary-expression before 'int'
   12 | void dfs(vector<int>&d,int v,int value){
      |                 ^~~
a.cc:12:24: error: expected primary-expression before 'int'
   12 | void dfs(vector<int>&d,int v,int value){
      |                        ^~~
a.cc:12:30: error: expected primary-expression before 'int'
   12 | void dfs(vector<int>&d,int v,int value){
      |                              ^~~
a.cc: In function 'int main()':
a.cc:22:12: error: 'cin' was not declared in this scope
   22 |     int N; cin >> N;
      |            ^~~
a.cc:23:5: error: 'vector' was not declared in this scope
   23 |     vector<vector<int>>g(N);
      |     ^~~~~~
a.cc:23:19: error: expected primary-expression before 'int'
   23 |     vector<vector<int>>g(N);
      |                   ^~~
a.cc:24:19: error: 'g' was not declared in this scope
   24 |     for(auto& v : g){
      |                   ^
a.cc:31:19: error: expected primary-expression before 'int'
   31 |     vector<vector<int>>pos(N,vector<int>(N,-1LL));
      |                   ^~~
a.cc:32:24: error: 'g' was not declared in this scope
   32 |     for(int i = 0; i < g.size(); ++i){
      |                        ^
a.cc:35:13: error: 'pos' was not declared in this scope
   35 |             pos[i][e] = j;
      |             ^~~
a.cc:38:19: error: expected primary-expression before 'bool'
   38 |     vector<vector<bool>>used(N,vector<bool>(N-1,false));
      |                   ^~~~
a.cc:39:5: error: 'edge' was not declared in this scope
   39 |     edge.resize(N*N);
      |     ^~~~
a.cc:40:12: error: expected primary-expression before 'int'
   40 |     vector<int>d(N*N,-1);
      |            ^~~
a.cc:41:12: error: expected primary-expression before 'int'
   41 |     vector<int>in(N*N);
      |            ^~~
a.cc: In lambda function:
a.cc:43:26: error: 'min' was not declared in this scope; did you mean 'main'?
   43 |         return make_pair(min(i,j), max(i,j));
      |                          ^~~
      |                          main
a.cc:43:36: error: 'max' was not declared in this scope; did you mean 'max_v'?
   43 |         return make_pair(min(i,j), max(i,j));
      |                                    ^~~
      |                                    max_v
a.cc:43:16: error: 'make_pair' was not declared in this scope
   43 |         return make_pair(min(i,j), max(i,j));
      |                ^~~~~~~~~
a.cc: In function 'int main()':
a.cc:47:16: error: 'used' was not declared in this scope
   47 |             if(used[i][j])continue;
      |                ^~~~
a.cc:49:22: error: 'g' was not declared in this scope
   49 |             auto e = g[i][j];
      |                      ^
a.cc:50:22: error: 'pos' was not declared in this scope
   50 |             int rj = pos[e][i];
      |                      ^~~
a.cc:54:17: error: 'in' was not declared in this scope; did you mean 'i'?
   54 |                 in[get_idx(nxt)]++;
      |                 ^~
      |                 i
a.cc:54:27: error: 'get_idx' cannot be used as a function
   54 |                 in[get_idx(nxt)]++;
      |                    ~~~~~~~^~~~~
a.cc:55:29: error: 'get_idx' cannot be used as a function
   55 |                 edge[get_idx(p)].push_back(get_idx(nxt));
      |                      ~~~~~~~^~~
a.cc:55:51: error: 'get_idx' cannot be used as a function
   55 |                 edge[get_idx(p)].push_back(get_idx(nxt));
      |                                            ~~~~~~~^~~~~
a.cc:59:17: error: 'in' was not declared in this scope; did you mean 'i'?
   59 |                 in[get_idx(nxt)]++;
      |                 ^~
      |                 i
a.cc:59:27: error: 'get_idx' cannot be used as a function
   59 |                 in[get_idx(nxt)]++;
      |                    ~~~~~~~^~~~~
a.cc:60:29: error: 'get_idx' cannot be used as a function
   60 |                 edge[get_idx(p)].push_back(get_idx(nxt));
      |                      ~~~~~~~^~~
a.cc:60:51: error: 'get_idx' cannot be used as a function
   60 |                 edge[get_idx(p)].push_back(get_idx(nxt));
      |                                            ~~~~~~~^~~~~
a.cc:62:13: error: 'used' was not declared in this scope
   62 |             used[i][j] = used[e][rj] = true;
      |             ^~~~
a.cc:67:12: error: 'in' was not declared in this scope; did you mean 'int'?
   67 |         if(in[p])continue;
      |            ^~
      |            int
a.cc:69:12: error: 'd' was not declared in this scope
   69 |         if(d[p]  == -1)
      |            ^
a.cc:70:13: error: 'dfs' was not declared in this scope
   70 |             dfs(d,p,1LL);
      |             ^~~
a.cc:73:26: error: 'puts' was not declared in this scope
   73 |     if(not valid) return puts("-1") * 0;
      |                          ^~~~
a.cc:74:5: error: 'cout' was not declared in this scope
   74 |     cout << *max_element(d.begin(), d.end()) << endl;
      |     ^~~~
a.cc:74:26: error: 'd' was not declared in this scope
   74 |     cout << *max_element(d.begin(), d.end()) << endl;
      |                          ^
a.cc:74:14: error: 'max_element' was not declared in this scope
   74 |     cout << *max_element(d.begin(), d.end()) << endl;
      |              ^~~~~~~~~~~
a.cc:74:49: error: 'endl' was not declared in this scope
   74 |     cout << *max_element(d.begin(), d.end()) << endl;
      |                                                 ^~~~