DuongNhi99

CJXAYDUNG (lqdoj) - Cau

Mar 26th, 2021
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 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<pi32> graph[N];
  12.  
  13. int CriticalEdge = 0;
  14. bool isCutEdge[N];
  15. int Num[N], Low[N], Time = 0;
  16.  
  17. void Tajan(int u, int p) {
  18.     Low[u] = Num[u] = ++Time;
  19.  
  20.     for (int i = 0; i < graph[u].size(); ++i) {
  21.         int v = graph[u][i].first;
  22.         int id = graph[u][i].second;
  23.  
  24.         if (v == p) continue;
  25.  
  26.         if (Num[v])
  27.             Low[u] = min(Low[u], Num[v]);
  28.         else {
  29.             Tajan(v, u);
  30.             Low[u] = min(Low[u], Low[v]);
  31.  
  32.             isCutEdge[id] |= Low[v] > Num[u];
  33.         }
  34.     }
  35. }
  36.  
  37. int main() {
  38. #ifdef LOCAL
  39.     freopen("in.txt", "r", stdin);
  40. #else
  41.     freopen("CJXAYDUNG.inp", "r", stdin);
  42.     freopen("CJXAYDUNG.out", "w", stdout);
  43. #endif // LOCAL
  44.     ios_base::sync_with_stdio(false);
  45.     cin.tie(NULL);
  46.  
  47.     cin >> n >> nE;
  48.     for (int i = 1; i <= nE; i++) {
  49.         int u, v; cin >> u >> v;
  50.         graph[u].push_back({v, i});
  51.         graph[v].push_back({u, i});
  52.     }
  53.  
  54.     for (int i = 1; i <= n; i++)
  55.         if (!Num[i]) Tajan(i, i);
  56.  
  57.     int Count = 0;
  58.     for (int i = 1; i <= n; i++)
  59.         if (isCutEdge[i]) Count++;
  60.  
  61.     cout << Count << '\n';
  62.     for (int i = 1; i <= n; i++)
  63.         if (isCutEdge[i])
  64.             cout << i << ' ';
  65.  
  66.     return 0;
  67. }
  68. // https://lqdoj.edu.vn/problem/cjxaydung
Advertisement
Add Comment
Please, Sign In to add comment