Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef pair <ll,ll> pi;
- typedef vector <ll> vi;
- const ld PI = 3.1415926535897932384626433832795L;
- const ld eps=1e-9;
- const int mod = 1e9 + 7;
- const int inf = INT_MAX;
- const int N = 10500, M = 100500;
- #define F first
- #define S second
- #define PB push_back
- #define rs resize
- ll n,m;
- ll ans=0;
- vi son[N];
- vi dp(N,0);
- vector <bool> used(N, 0);
- ll fun(ll v){
- if (used[v]) return dp[v];
- for(auto e:son[v]){
- dp[v] = max(dp[v],fun(e) + 1);
- }
- return dp[v];
- }
- int main()
- {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- cout<<fixed<<setprecision(20);
- // freopen("longpath.in", "r", stdin);
- // freopen("longpath.out", "w", stdout);
- cin>>n>>m;
- for(int i=0;i<m;i++)
- {
- ll v,to;
- cin>>v>>to;
- son[v].PB(to);
- }
- for(int i=1;i<=n;i++)
- {
- ans = max(ans, fun(i));
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement