fork download
  1. /*
  2. */
  3.  
  4. //#pragma comment(linker, "/STACK:16777216")
  5. #include <fstream>
  6. #include <iostream>
  7. #include <string>
  8. #include <complex>
  9. #include <math.h>
  10. #include <set>
  11. #include <vector>
  12. #include <map>
  13. #include <queue>
  14. #include <stdio.h>
  15. #include <stack>
  16. #include <algorithm>
  17. #include <list>
  18. #include <ctime>
  19. #include <memory.h>
  20. #include <ctime>
  21. #include <assert.h>
  22.  
  23. #define y0 sdkfaslhagaklsldk
  24. #define y1 aasdfasdfasdf
  25. #define yn askfhwqriuperikldjk
  26. #define j1 assdgsdgasghsf
  27. #define tm sdfjahlfasfh
  28. #define lr asgasgash
  29.  
  30. #define eps 1e-9
  31. #define M_PI 3.141592653589793
  32. //#define bs 1000000007
  33. #define bsize 512
  34.  
  35. using namespace std;
  36.  
  37. int n,m;
  38. vector<int> g[1<<20];
  39. int used[1<<20];
  40. int ans[1<<20];
  41.  
  42. void solve(int v)
  43. {
  44. cout<<v<<endl;
  45. used[v]=1;
  46. for (int i=0;i<g[v].size();i++)
  47. {
  48. int to=g[v][i];
  49. if (used[to])
  50. continue;
  51. solve(to);
  52. }
  53.  
  54. for (int i=0;i<g[v].size();i++)
  55. {
  56. int to=g[v][i];
  57. ans[v]=max(ans[v],ans[to]+1);
  58. }
  59. }
  60.  
  61. int main(){
  62. //freopen("center.in","r",stdin);
  63. //freopen("center.out","w",stdout);
  64. //freopen("F:/in.txt","r",stdin);
  65. //freopen("F:/output.txt","w",stdout);
  66. ios_base::sync_with_stdio(0);
  67. //cin.tie(0);
  68.  
  69. cin>>n>>m;
  70. for (int i=0;i<m;i++)
  71. {
  72. int a,b;
  73. cin>>a>>b;
  74. g[a].push_back(b);
  75. }
  76.  
  77. solve(1);
  78. cout<<ans[1]<<endl;
  79.  
  80. //cin.get();cin.get();
  81. return 0;}
Success #stdin #stdout 0s 23936KB
stdin
4 4
1 2
2 3
1 4
4 2
stdout
1
2
3
4
3