Language: C++

#include <bits/stdc++.h>

#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

//#define max(a,b) a>b?a:b
//#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int sum() { return 0; }

template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }



vector<vector<int> > gr[100005];
int dp[100005];
int n,m;
ll cnt =0;
ll dfs(int i){
	if(dp[i] != -1) return dp[i];
	cnt = 0;
	for (int j = 0; j < gr[i].size(); ++j)
	{	int f = gr[i][j];
		//if(vis[f] != true){
			//cnt++;
			cnt =  max(cnt ,  dfs(f) + 1);
		//}
	}
	return dp[i] = cnt;



}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>n>>m;
	//vis.assign(n ,false);
	//gr.assign( n , vector<int>());
	int a,b;
	for (int i = 0; i < m; ++i)
	{
		cin>>a>>b;
		a--;b--;
		gr[a].push_back(b);
	}
	ll ans = -1;
	REP(i,n)dp[i] = -1;
	for (int i = 0; i < n; ++i)
	{	cnt = 0;
	     //vis.clear();
	     //vis.assign(n , false);

		 ans = max(ans , (ll)dfs(i));
	}
	cout<<ans<<"\n"; 
	return 0;
}


Compiler output:
a.cc: In function 'long long int dfs(int)':
a.cc:46:32: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'int' in initialization
   46 |         {       int f = gr[i][j];
      |                                ^
a.cc: In function 'int main()':
a.cc:68:32: error: no matching function for call to 'std::vector<std::vector<int> >::push_back(int&)'
   68 |                 gr[a].push_back(b);
      |                 ~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; value_type = std::vector<int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'int' to 'const std::vector<std::vector<int> >::value_type&' {aka 'const std::vector<int>&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; value_type = std::vector<int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'int' to 'std::vector<std::vector<int> >::value_type&&' {aka 'std::vector<int>&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~