Language: C++

// link:
// [prajwal1721]
// g++ -Wall -Wextra -Wshadow filename.cpp
// ./a.out >input <output
/*comments:
*/



#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b))
#define bits(x) __builtin_popcountll(x)
#define vi              vector<int>
#define vl              vector<ll>
#define all(v)          v.begin(),v.end()
#define UNIQUE(X)       (X).erase(unique(all(X)),(X).end())



typedef long long int ll;
vector<ll> topological;
vector<ll> adj[100006];
ll visit[100005]={0};
void dfs(int n)
{
    visit[n]=1;
    for(auto i: adj[n])
    {
        if(visit[i]==0)dfs(i);
    }
    if(visit[n]==1)
        {
            topological.push_back(n);
            visit[n]=2;
        }
}
void solve()
{
    ll n,t,m,u,v;cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>u>>v;
        adj[u].push_back(v);
    }
    for(int i=1;i<=n;i++)
        visit[i]=0;
    for(int i=1;i<=n;i++)
       if(!visit[i])
        dfs(i);
    reverse(topological.begin(),topological.end());
    // for(auto i:topological)cout<<i<<" ";cout<<"\n";
    ll dist[n+1]={0},mx=0;
    for(auto i:topological)
    {
        for(auto j:adj[i])
            dist[j]=max(dist[j],dist[i]+1);
    }
    for(int i=1;i<=n;i++)mx=max(mx,dist[i]);
    cout<<mx<<"\n";
}


int main()
{ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // ll t;cin>>t;
    // cout<<t<<"Hi test complete\n";
    // while(t--)
        {
            solve();
        }


    return 0;
}

Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:29:5: error: reference to 'visit' is ambiguous
   29 |     visit[n]=1;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:10:
/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:26:4: note:                 'll visit [100005]'
   26 | ll visit[100005]={0};
      |    ^~~~~
a.cc:32:12: error: reference to 'visit' is ambiguous
   32 |         if(visit[i]==0)dfs(i);
      |            ^~~~~
/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:26:4: note:                 'll visit [100005]'
   26 | ll visit[100005]={0};
      |    ^~~~~
a.cc:34:8: error: reference to 'visit' is ambiguous
   34 |     if(visit[n]==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:26:4: note:                 'll visit [100005]'
   26 | ll visit[100005]={0};
      |    ^~~~~
a.cc:37:13: error: reference to 'visit' is ambiguous
   37 |             visit[n]=2;
      |             ^~~~~
/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:26:4: note:                 'll visit [100005]'
   26 | ll visit[100005]={0};
      |    ^~~~~
a.cc: In function 'void solve()':
a.cc:49:9: error: reference to 'visit' is ambiguous
   49 |         visit[i]=0;
      |         ^~~~~
/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:26:4: note:                 'll visit [100005]'
   26 | ll visit[100005]={0};
      |    ^~~~~
a.cc:51:12: error: reference to 'visit' is ambiguous
   51 |        if(!visit[i])
      |            ^~~~~
/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:26:4: note:                 'll visit [100005]'
   26 | ll visit[100005]={0};
      |    ^~~~~