fork(3) download
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. /*
  5. #define
  6. #define
  7. */
  8. vector < int > Graph[100000];
  9. int visit[100000];
  10. int dis[100000], baack[100000];
  11. int timer;
  12. int component;
  13. int root, degreeOfRoot;
  14.  
  15. void findArt(int u)
  16. {
  17. visit[u] = 1;
  18. timer++;
  19. baack[u]=dis[u]=timer;
  20. for(int i=0; i<Graph[u].size(); i++)
  21. {
  22. int v = Graph[u][i];
  23. if(!visit[v])
  24. {
  25. findArt(v);
  26. if(u==root) degreeOfRoot++;
  27. if(degreeOfRoot>=2) cout << u << " ";
  28.  
  29. baack[u] = min(baack[u], baack[v]);
  30. if(baack[v]>=dis[u] && u!=root) cout << u << " ";
  31. }
  32. else
  33. baack[u] = min(baack[u], dis[v]);
  34. }
  35. }
  36.  
  37. int main()
  38. {
  39. int i, j, k;
  40. int n, u, v;
  41.  
  42. //init(n);
  43. cin >> n;
  44.  
  45. while(cin>>u>>v)
  46. {
  47. Graph[u].push_back(v);
  48. Graph[v].push_back(u);
  49. }
  50.  
  51.  
  52. root = 1;
  53. findArt(root);
  54. cout << endl;
  55. for(i=1; i<=n; i++) cout << baack[i] << " ";
  56.  
  57. return 0;
  58. }
  59. /*
  60. 9
  61. 1 2
  62. 1 5
  63. 1 4
  64. 2 3
  65. 3 4
  66. 4 5
  67. 4 6
  68. 4 9
  69. 6 9
  70. 6 7
  71. 6 8
  72. 7 8
  73. 8 9
  74. */
  75.  
  76.  
Success #stdin #stdout 0s 5688KB
stdin
Standard input is empty
stdout