DuongNhi99

CJPHANCONG (lqdoj) - Khop

Mar 26th, 2021
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using i64 = long long;
  5. using pi32 = pair<int, int>;
  6. using pi64 = pair<i64, i64>;
  7.  
  8. const int N = 1e5 + 5;
  9.  
  10. int n, nE;
  11. vector<int> graph[N];
  12.  
  13. bool CriticalNode[N];
  14. int Num[N], Low[N], Time = 0;
  15.  
  16. void visit(int u, int p) {
  17.     int NumChild = 0;
  18.     Low[u] = Num[u] = ++Time;
  19.  
  20.     for (int v : graph[u])
  21.         if (v != p) {
  22.             if (Num[v] != 0)
  23.                 Low[u] = min(Low[u], Num[v]);
  24.             else {
  25.                 visit(v, u);
  26.                 NumChild++;
  27.                 Low[u] = min(Low[u], Low[v]);
  28.  
  29.                 if (u == p) {
  30.                     if (NumChild >= 2)
  31.                         CriticalNode[u] = true;
  32.                 } else {
  33.                     if (Low[v] >= Num[u])
  34.                         CriticalNode[u] = true;
  35.                 }
  36.             }
  37.         }
  38. }
  39.  
  40. int main() {
  41. #ifdef LOCAL
  42.     freopen("in.txt", "r", stdin);
  43. #else
  44.     freopen("CJPHANCONG.inp", "r", stdin);
  45.     freopen("CJPHANCONG.out", "w", stdout);
  46. #endif // LOCAL
  47.     ios_base::sync_with_stdio(false);
  48.     cin.tie(NULL);
  49.  
  50.     cin >> n >> nE;
  51.     for (int i = 1; i <= nE; i++) {
  52.         int u, v; cin >> u >> v;
  53.         graph[u].push_back(v);
  54.         graph[v].push_back(u);
  55.     }
  56.  
  57.     for (int i = 1; i <= n; i++)
  58.         if (!Num[i]) visit(i, i);
  59.  
  60.     int Count = 0;
  61.     for (int i = 1; i <= n; i++)
  62.         if (CriticalNode[i]) Count++;
  63.  
  64.     cout << Count << '\n';
  65.     for (int i = 1; i <= n; i++)
  66.         if (CriticalNode[i])
  67.             cout << i << ' ';
  68.  
  69.     return 0;
  70. }
  71. // https://lqdoj.edu.vn/problem/cjphancong
Advertisement
Add Comment
Please, Sign In to add comment