Language: C++

#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#define lli long long int
#define mp make_pair
#define pb push_back
using namespace std;

const lli mod = 998244353;

lli power(lli x, lli y) {
    // x %= mod;
    if (y == 0) return 1;
    // return ((y % 2 == 1 ? x : 1) * power(x * x, y / 2)) % mod;
    return ((y % 2 == 1 ? x : 1) * power(x * x, y / 2));
}

vector <long long int> primeNumbers;

void SieveOfEratosthenes(int n){
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++){ 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++){
      if (prime[p]){
        primeNumbers.push_back(p);
      }
    }        
}

#define MAXN 100005
vector < vector < int >  > v(MAXN);
int visit[MAXN];
int d[MAXN];
int deg[MAXN];

// void dfs(int index, int parent){
//   visit[index] = 1;
//   for(int i = 0;i<v[parent].size();i++){
//     int node = v[parent][i];
//     if(visit[node]) continue;
//     else if (!binary_search(v[index].begin(),v[index].end(),node)){
//       visit[node] = 1;
//       dfs(node,index);
//     }
//   }
// }
void pre(){
}

void solve(){
  int n,m;
  cin>>n>>m;
  for(int i = 0;i<m;i++){
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
    deg[y]++;
  }
  queue < int > q;
  for(int i = 1;i<=n;i++){
    if(deg[i] == 0){
      q.push(i);
    }
  }

  while(!q.empty()){
    int vertex = q.front();
    q.pop();
    for(int i = 0;i<v[vertex].size();i++){
      int node = v[vertex][i];
      if(visit[node] == 1) continue;
      else{
        deg[node]--;
        d[node] = max(d[node],d[vertex] + 1);
        if(deg[node] == 0){
          visit[node] = 1;
          q.push(node);
        }
      }
    }
  }

  int ans = 0;
  for(int i = 1;i<=n;i++) ans = max(ans,d[i]);
    cout<<ans;
}
 
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
 
  int t;
  // cin>>t;
  // scanf("%d",&t);
  t = 1;
  pre();
  while(t--){
    // cout<<
    solve();
 
    if(t>0){
      cout<<endl;
      // printf("\n");
    } 
  }
 
 
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
  return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:80:10: error: reference to 'visit' is ambiguous
   80 |       if(visit[node] == 1) continue;
      |          ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:5:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:41:5: note:                 'int visit [100005]'
   41 | int visit[MAXN];
      |     ^~~~~
a.cc:85:11: error: reference to 'visit' is ambiguous
   85 |           visit[node] = 1;
      |           ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:41:5: note:                 'int visit [100005]'
   41 | int visit[MAXN];
      |     ^~~~~