fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. #include <vector>
  5. #include <string>
  6. #include <set>
  7. #include <map>
  8. #include <algorithm>
  9.  
  10.  
  11. using namespace std;
  12. vector<int>siz;
  13. void IS_CUTPOINT(int u){
  14. cout << u << endl;
  15. }
  16.  
  17. const int MAXN =20001;
  18. vector<int> g[MAXN];
  19. bool used[MAXN];
  20. int timer, tin[MAXN], fup[MAXN];
  21.  
  22. void dfs (int v, int p = -1) {
  23. used[v] = true;
  24. tin[v] = fup[v] = timer++;
  25. int children = 0;
  26. for (size_t i=0; i<g[v].size(); ++i) {
  27. int to = g[v][i];
  28. if (to == p) continue;
  29. if (used[to])
  30. fup[v] = min (fup[v], tin[to]);
  31. else {
  32. dfs (to, v);
  33. fup[v] = min (fup[v], fup[to]);
  34. if (fup[to] >= tin[v] && p != -1)
  35. IS_CUTPOINT(v);
  36. ++children;
  37. }
  38. }
  39. if (p == -1 && children > 1)
  40. IS_CUTPOINT(v);
  41. }
  42.  
  43. int main() {
  44. int n,m,a,b;
  45. cin >> n >> m;
  46. for(int i=0;i<m;i++){
  47. cin >> a >>b;
  48. g[a].push_back(b);
  49. g[b].push_back(a);
  50. }
  51. for(int i=0;i<n;i++){
  52. for(auto j:g[i]){
  53. cout << j << " ";
  54. }
  55. cout << endl;
  56. }
  57. timer = 0;
  58. for (int i=0; i<n; ++i)
  59. used[i] = false;
  60. dfs (0);
  61.  
  62.  
  63.  
  64. }
Success #stdin #stdout 0s 15880KB
stdin
9 12
1 2
2 3
4 5
2 6
2 7
8 9
1 3
1 4
1 5
6 7
3 8
3 9
stdout
2 3 4 5 
1 3 6 7 
2 1 8 9 
5 1 
4 1 
2 7 
2 6 
9 3