Language: C++

#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define vb vector<bool>
using namespace std;

ostream& operator << (ostream &out, vector<int> &v) { for(auto a:v) out << a<<" "; out<<endl; }

const int maxn=100005;
vi G[maxn];
vb visited[maxn];
ll dp[maxn];

int dfs(int src)
{
    if ( visited[src] ) return dp[src];

    visited[src]=1;
    if(G[src].empty()) dp[src]=return 0;

    int len=0;
    for(auto v: G[src])
    {
        len=max(len,1+dfs(v));
    }
    dp[src]=len;
}
int main()
{
    fast_cin
    int n,m;

    cin>>n>>m;
    for(int i = 1 ; i <= m ; i++)
    {
        int u,v;
        cin >> u >> v;
        G[u].pb(v);
    }
    for(int i=n;i>=1;i--)
    {
        if(G[i].size())//there is an edge leading from this to v.
            dfs(i);
    }
    cout << *max_element(dp,dp+n+1)<<endl;
}


Compiler output:
a.cc: In function 'std::ostream& operator<<(std::ostream&, std::vector<int>&)':
a.cc:22:95: warning: no return statement in function returning non-void [-Wreturn-type]
   22 | ostream& operator << (ostream &out, vector<int> &v) { for(auto a:v) out << a<<" "; out<<endl; }
      |                                                                                               ^
a.cc: In function 'int dfs(int)':
a.cc:31:21: error: could not convert 'visited[src]' from 'std::vector<bool>' to 'bool'
   31 |     if ( visited[src] ) return dp[src];
      |          ~~~~~~~~~~~^
      |                     |
      |                     std::vector<bool>
a.cc:33:18: error: no match for 'operator=' (operand types are 'std::vector<bool>' and 'int')
   33 |     visited[src]=1;
      |                  ^
In file included from /usr/include/c++/14/vector:67,
                 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_bvector.h:894:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(const std::vector<bool, _Alloc>&) [with _Alloc = std::allocator<bool>]'
  894 |       operator=(const vector& __x)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:894:31: note:   no known conversion for argument 1 from 'int' to 'const std::vector<bool>&'
  894 |       operator=(const vector& __x)
      |                 ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:926:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(std::vector<bool, _Alloc>&&) [with _Alloc = std::allocator<bool>]'
  926 |       operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:926:26: note:   no known conversion for argument 1 from 'int' to 'std::vector<bool>&&'
  926 |       operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:952:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(std::initializer_list<bool>) [with _Alloc = std::allocator<bool>]'
  952 |       operator=(initializer_list<bool> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:952:40: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<bool>'
  952 |       operator=(initializer_list<bool> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:34:32: error: expected primary-expression before 'return'
   34 |     if(G[src].empty()) dp[src]=return 0;
      |                                ^~~~~~
a.cc:41:12: warning: control reaches end of non-void function [-Wreturn-type]
   41 |     dp[src]=len;
      |     ~~~~~~~^~~~