orazma

a_and_b.cpp

Apr 16th, 2026
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define f first
  3. #define s second
  4. #define pb push_back
  5. #define mp make_pair
  6. #define ll long long
  7.  
  8. #define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  9.  
  10. using namespace std;
  11. const int INF = 1e9 + 1;
  12. const int MAXN = 2e5 + 10;
  13. int tin[MAXN], a[2 * MAXN], tout[MAXN], ans[MAXN], col[MAXN], cnt[MAXN], cntCnt[MAXN];
  14. int n, m;
  15. pair <pair <int, int>, pair <int, pair <int, int> > > b[MAXN];
  16. int timer = 0;
  17. bool was[MAXN];
  18. vector <int> g[MAXN];
  19.  
  20. void dfs(int v, int pr = -1){
  21.     was[v] = 1;
  22.     tin[v] = ++timer;
  23.     fup[v] = tin[v];
  24.     for (int to : g[v]){
  25.         if (!was[to]){
  26.             dfs(to, v);
  27.             if (tin[v] > fup[to]){
  28.                 is_bridge(v, to);
  29.             }
  30.             fup[v] = min(fup[v], fup[to]);
  31.         }
  32.         else if (to != pr){
  33.             fup[v] = min(fup[v], tin[to]);
  34.         }
  35.     }
  36. }
  37.  
  38.  
  39. void dfs(int v, int pr = -1){
  40.     was[v] = 1;
  41.     tin[v] = ++timer;
  42.     fup[v] = tin[v];
  43.     int child = 0;
  44.     for (int to : g[v]){
  45.         if (!was[to]){
  46.             child++;
  47.             dfs(to, v);
  48.             if (tin[v] >= fup[to] && pr != -1){
  49.                 is_point(v);
  50.             }
  51.             fup[v] = min(fup[v], fup[to]);
  52.         }
  53.         else if (to != pr){
  54.             fup[v] = min(fup[v], tin[to]);
  55.         }
  56.     }
  57.     if (pr == -1 && child > 1){
  58.         is_point(v);
  59.     }
  60. }
  61. void solve(){
  62.     int n, m;
  63.     cin >> n >> m;
  64.  
  65.     for (int i = 1; i <= m; i++){
  66.         int x, y;
  67.         cin >> x >> y;
  68.         g[x].pb(y);
  69.         g[y].pb(x);
  70.     }
  71.  
  72.     for (int i = 1; i <= n; i++){
  73.         if (!was[i]){
  74.             dfs(i, -1);
  75.         }
  76.     }
  77. }
  78. int main() {
  79.     IOS;
  80.     //freopen("rmq.in", "r", stdin);
  81.     //freopen("rmq.out", "w", stdout);
  82.     int t = 1;
  83.    // cin >> t;
  84.     while(t--){
  85.         solve();
  86.     }
  87.     return 0;
  88. }
  89.  
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment