Advertisement
Guest User

Untitled

a guest
May 19th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef long double ld;
  6. typedef pair <ll,ll> pi;
  7. typedef vector <ll> vi;
  8.  
  9. const ld PI =  3.1415926535897932384626433832795L;
  10. const ld eps=1e-9;
  11. const int mod = 1e9 + 7;
  12. const int inf = INT_MAX;
  13. const int N = 10500, M = 100500;
  14.  
  15.  
  16. #define F first
  17. #define S second
  18. #define PB push_back
  19. #define rs resize
  20.  
  21. ll n,m;
  22. ll ans=0;
  23.  
  24. vi son[N];
  25. vi dp(N,0);
  26. vector <bool> used(N, 0);
  27.  
  28. ll fun(ll v){
  29.     if (used[v]) return dp[v];
  30.    
  31.     for(auto e:son[v]){
  32.         dp[v] = max(dp[v],fun(e) + 1);
  33.     }
  34.    
  35.     return dp[v];
  36. }
  37.  
  38. int main()
  39. {
  40.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  41.     cout<<fixed<<setprecision(20);
  42. //    freopen("longpath.in", "r", stdin);
  43. //    freopen("longpath.out", "w", stdout);
  44.     cin>>n>>m;
  45.     for(int i=0;i<m;i++)
  46.     {
  47.         ll v,to;
  48.         cin>>v>>to;
  49.         son[v].PB(to);
  50.     }
  51.     for(int i=1;i<=n;i++)
  52.     {
  53.         ans = max(ans, fun(i));
  54.     }
  55.     cout<<ans<<endl;
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement