SHARE
TWEET

Untitled

a guest May 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top