Language: C++

#include<bits/stdc++.h>

using namespace std;

const int cons = 1e5 + 5;
vector<int> graph[cons];
int indegree[cons]; 
int distance[cons];
bool visited[cons];

void dfs(int a) {
    
    assert(!visited[a]);
    visited[a] = true;

    for(int b : graph[a]) {

        distance[b] = max(distance[b], distance[a] + 1);
        --indegree[b];
        if(indegree[b] == 0) {
            dfs(b);
        }
    }
}

int main() {

    int n, m;
    cin >> n >> m;

    for(int i = 0 ; i < m; i++) {

        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        ++indegree[b];
    }

    for(int i = 1; i <= n; ++i) {

        if(!visited[i] && indegree[i] == 0) {

            dfs(i);
        }
    }

    int answer = 0;
    for(int i = 1; i <= n; ++i) {

        answer = max(answer, distance[i]);
    }

    cout << answer;

    return 0;
}

Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:18:9: error: reference to 'distance' is ambiguous
   18 |         distance[b] = max(distance[b], distance[a] + 1);
      |         ^~~~~~~~
In file included from /usr/include/c++/14/filesystem:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:200,
                 from a.cc:1:
/usr/include/c++/14/bits/fs_path.h:1431:1: note: candidates are: 'std::ptrdiff_t std::distance(filesystem::__cxx11::path::iterator, filesystem::__cxx11::path::iterator)'
 1431 | distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
      | ^~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 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_iterator_base_funcs.h:148:5: note:                 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
a.cc:8:5: note:                 'int distance [100005]'
    8 | int distance[cons];
      |     ^~~~~~~~
a.cc:18:27: error: reference to 'distance' is ambiguous
   18 |         distance[b] = max(distance[b], distance[a] + 1);
      |                           ^~~~~~~~
/usr/include/c++/14/bits/fs_path.h:1431:1: note: candidates are: 'std::ptrdiff_t std::distance(filesystem::__cxx11::path::iterator, filesystem::__cxx11::path::iterator)'
 1431 | distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
      | ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:                 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
a.cc:8:5: note:                 'int distance [100005]'
    8 | int distance[cons];
      |     ^~~~~~~~
a.cc:18:40: error: reference to 'distance' is ambiguous
   18 |         distance[b] = max(distance[b], distance[a] + 1);
      |                                        ^~~~~~~~
/usr/include/c++/14/bits/fs_path.h:1431:1: note: candidates are: 'std::ptrdiff_t std::distance(filesystem::__cxx11::path::iterator, filesystem::__cxx11::path::iterator)'
 1431 | distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
      | ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:                 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
a.cc:8:5: note:                 'int distance [100005]'
    8 | int distance[cons];
      |     ^~~~~~~~
a.cc: In function 'int main()':
a.cc:50:30: error: reference to 'distance' is ambiguous
   50 |         answer = max(answer, distance[i]);
      |                              ^~~~~~~~
/usr/include/c++/14/bits/fs_path.h:1431:1: note: candidates are: 'std::ptrdiff_t std::distance(filesystem::__cxx11::path::iterator, filesystem::__cxx11::path::iterator)'
 1431 | distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
      | ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:                 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
a.cc:8:5: note:                 'int distance [100005]'
    8 | int distance[cons];
      |     ^~~~~~~~