orazma

mosty.cpp

Mar 31st, 2026
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define f first
  5. #define s second
  6. #define ll long long
  7. #define sz(x) int(x.size())
  8. #define all(x) x.begin(), x.end()
  9. #define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  10. #define cYES cout << "YES\n"
  11. #define cNO cout << "NO\n"
  12. #define ins insert
  13. #define mas(a, n) a + 1, a + n + 1
  14. #define lll __int128
  15. const int MAXN = int(1e5) + 3;
  16. const int MOD = int(1e9) + 7;
  17. const ll INF = int(1e9) + 7;
  18. int timer = 0;
  19. void dfs(int v, int pr = -1){
  20.     was[v] = 1;
  21.     tin[v] = ++timer;
  22.     fup[v] = tin[v];
  23.  
  24.     for (int to : g[v]){
  25.         if (!was[to]){
  26.             dfs(to, v);
  27.             if (fup[to] > tin[v]){
  28.                 is_bridge(v, to);
  29.             }
  30.             fup[v] = min(fup[v], fup[to]);
  31.         }
  32.         else if (was[to] == 1 && to != pr){
  33.             fup[to] = min(fup[to], tin[v]);
  34.         }
  35.     }
  36. }
  37.  
  38. void dfs(int v, int pr = -1){
  39.     was[v] = 1;
  40.     tin[v] = ++timer;
  41.     fup[v] = tin[v];
  42.     int child = 0;
  43.  
  44.     for (int to : g[v]){
  45.         if (!was[to]){
  46.             child++;
  47.             dfs(to, v);
  48.             if (pr != -1 && fup[to] >= tin[v]){
  49.                 is_point(v);
  50.             }
  51.             fup[v] = min(fup[v], fup[to]);
  52.         }
  53.         else if (was[to] == 1 && to != pr){
  54.             fup[to] = min(fup[to], tin[v]);
  55.         }
  56.     }
  57.     if (pr == -1 && child > 1){
  58.         is_point(v);
  59.     }
  60. }
  61.  
  62. int main() {
  63.     IOS;
  64.  
  65.     int n, m;
  66.     cin >> n >> m;
  67.  
  68.     for (int i = 1; i <= m; i++){
  69.         int x, y;
  70.         cin >> x >> y;
  71.  
  72.         g[x].push_back(y);
  73.         g[y].push_back(x);
  74.     }
  75.  
  76.     for (int i = 1; i <= n; i++){
  77.         if (!was[i])
  78.             dfs(i, -1);
  79.     }
  80.  
  81.  
  82.     return 0;
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment