Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mset(m,v) memset(m,v,sizeof(m))
#define pr(a,s) printf("Case #%lld: %lld\n",a,s)
#define mod 1000000007
#define mp make_pair
#define all(a)                a.begin(),a.end()
#define pb push_back
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define se second
#define fi first
#define pi 3.14159265358979323
#define pii pair<ll,ll>
 
const ll inf = 1e7;
const int MAXM = 1e5+4;
const int MAXN = 1e5+10;

vector<int> v[MAXM];
bool visit[MAXM];
vector<int> top_sort;

void DFS(int x) 
{
	visit[x] = 1;
	for (auto it : v[x]) {
		if (!visit[it])
			DFS(it);
	}
	top_sort.pb(x);
}

int DFS1(int x)
{
	visit[x] = 1;
	int ret = 1;
	for (auto it : v[x]) {
		ret = max(ret, 1+DFS1(it));
	}
	return ret;
}

int main() 
{
	int n,m;
	cin>>n>>m;
	mset(dp,-1);
	for (int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}
	for (int i=1;i<=n;i++){
		if (!visit[i]) {
			DFS(i);
		}
	}
	reverse(all(top_sort));
	mset(visit, false);
	int ans = 1;
	for (int i=0;i<top_sort.size();i++) {
		if(!visit[top_sort[i]]) {
			ans = max(ans, DFS1(top_sort[i]));
		}
	}
	cout << ans-1 << endl;
	return 0;
}

Compiler output:
a.cc: In function 'void DFS(int)':
a.cc:27:9: error: reference to 'visit' is ambiguous
   27 |         visit[x] = 1;
      |         ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc: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:22:6: note:                 'bool visit [100004]'
   22 | bool visit[MAXM];
      |      ^~~~~
a.cc:29:22: error: reference to 'visit' is ambiguous
   29 |                 if (!visit[it])
      |                      ^~~~~
/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:22:6: note:                 'bool visit [100004]'
   22 | bool visit[MAXM];
      |      ^~~~~
a.cc: In function 'int DFS1(int)':
a.cc:37:9: error: reference to 'visit' is ambiguous
   37 |         visit[x] = 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:22:6: note:                 'bool visit [100004]'
   22 | bool visit[MAXM];
      |      ^~~~~
a.cc: In function 'int main()':
a.cc:49:14: error: 'dp' was not declared in this scope; did you mean 'dup'?
   49 |         mset(dp,-1);
      |              ^~
a.cc:4:26: note: in definition of macro 'mset'
    4 | #define mset(m,v) memset(m,v,sizeof(m))
      |                          ^
a.cc:56:22: error: reference to 'visit' is ambiguous
   56 |                 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:22:6: note:                 'bool visit [100004]'
   22 | bool visit[MAXM];
      |      ^~~~~
a.cc:61:14: error: reference to 'visit' is ambiguous
   61 |         mset(visit, false);
      |              ^~~~~
a.cc:4:26: note: in definition of macro 'mset'
    4 | #define mset(m,v) memset(m,v,sizeof(m))
      |                          ^
/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:22:6: note:                 'bool visit [100004]'
   22 | bool visit[MAXM];
      |      ^~~~~
a.cc:61:14: error: reference to 'visit' is ambiguous
   61 |         mset(visit, false);
      |              ^~~~~
a.cc:4:37: note: in definition of macro 'mset'
    4 | #define mset(m,v) memset(m,v,sizeof(m))
      |                                     ^
/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:22:6: note:                 'bool visit [100004]'
   22 | bool visit[MAXM];
      |      ^~~~~
a.cc:64:21: error: reference to 'visit' is ambiguous
   64 |                 if(!visit[top_sort[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:22:6: note:                 'bool visit [100004]'
   22 | bool visit[MAXM];
      |      ^~~~~