Language: C++

#include <bits/stdc++.h>
#include <iostream>
#include <queue>

using namespace std;

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

struct Edge {
    long long to;
};

using Graph = vector<vector<Edge>>;

int find[2000000];  
int d[2000000];     

int dfs(const Graph &G, int n) {
  
    if (find[n] == 2) return d[n];
    seen[n] = 1;
    for (auto e : G[n]) {
      
        if (find[e.to] == 1) {  
          
            cout << -1 << endl;
          
            exit(0);
        }
        chmax(d[n], dfs(G, e.to) + 1);
    }
    find[n] = 2;
    return d[n];
}
int main() {
    long long N;
  
    cin >> N;
  
    Graph G(N * (N - 1) / 2 + 1);
  
    for(int i=0; i<N; i++) {
        int n = 0;
       for(int k=0;k<n-1;k++) {
            int j;
         
            cin >> j;
         
            j--;
         
          if (i < j) swap(i, j);
          
            int ne =  i * (i - 1) / 2 + j + 1;;
          
            G[n].push_back({ne});
          
            n = ne;
        }
    }
  
    cout << dfs(G, 0) << endl;
  
    return 0;
}


Compiler output:
a.cc: In function 'int dfs(const Graph&, int)':
a.cc:27:9: error: reference to 'find' is ambiguous
   27 |     if (find[n] == 2) return d[n];
      |         ^~~~
In file included from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54,
                 from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidates are: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
In file included from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:                 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:                 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
a.cc:22:5: note:                 'int find [2000000]'
   22 | int find[2000000];
      |     ^~~~
a.cc:28:5: error: 'seen' was not declared in this scope
   28 |     seen[n] = 1;
      |     ^~~~
a.cc:31:13: error: reference to 'find' is ambiguous
   31 |         if (find[e.to] == 1) {
      |             ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidates are: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:                 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:                 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
a.cc:22:5: note:                 'int find [2000000]'
   22 | int find[2000000];
      |     ^~~~
a.cc:39:5: error: reference to 'find' is ambiguous
   39 |     find[n] = 2;
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidates are: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:                 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:                 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
a.cc:22:5: note:                 'int find [2000000]'
   22 | int find[2000000];
      |     ^~~~