Advertisement
Raslboyy

112824

Nov 9th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. //#include <chrono>
  3. //#include <fstream>
  4. //#include <bits/stdc++.h>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. #define mp make_pair
  9. #define pb push_back
  10. #define eb emplace_back
  11. #define f first
  12. #define s second
  13. #define sz(x) (int)x.size()
  14. #define all(x) begin(x), end(x)
  15. #define rall(x) rbegin(x), rend(x)
  16.  
  17. using namespace std;
  18.  
  19. typedef unsigned long long ull;
  20. typedef long long ll;
  21. typedef long double ld;
  22. typedef pair<int, int> pi;
  23. typedef pair<ll, ll> pl;
  24.  
  25. int count_bridge = 0;
  26. int timer = 0;
  27. int n, m;
  28. vector<vector<bool>> vec;
  29. vector<int> tin;
  30. vector<int> fup;
  31. vector<bool> used;
  32.  
  33. void dfs(int cur_v, int p) {
  34.     used[cur_v] = true;
  35.     fup[cur_v] = tin[cur_v] = timer++;
  36.     for (int i = 0; i < n; i++) {
  37.         if (i == p) continue;
  38.         if (vec[cur_v][i] && used[i]) fup[cur_v] = min(fup[cur_v], tin[i]);
  39.         else if (vec[cur_v][i]) {
  40.             dfs(i, cur_v);
  41.             fup[cur_v] = min(fup[cur_v], fup[i]);
  42.             if (fup[i] > tin[cur_v])
  43.                 count_bridge++;
  44.         }
  45.     }
  46.    
  47. }
  48.  
  49. int main() {
  50.     /*ifstream cin("in.txt");
  51.     ofstream cout("out.txt");
  52.     auto start_time = chrono::high_resolution_clock::now();*/
  53.  
  54.     ios::sync_with_stdio(false);
  55.     cin.tie(0);
  56.     cout.tie(0);
  57.  
  58.     cin >> n >> m;
  59.     vec.assign(n, vector<bool>(n));
  60.     tin.assign(n, 0);
  61.     fup.assign(n, 0);
  62.     used.assign(n, false);
  63.     for (int i = 0; i < m; i++) {
  64.         int a, b;
  65.         cin >> a >> b;
  66.         vec[--a][--b] = true;
  67.         vec[b][a] = true;
  68.     }
  69.     for (int i = 0; i < n; i++)
  70.         if (!used[i])
  71.             dfs(i, -1);
  72.     cout << m - count_bridge << "\n";
  73.    
  74.     /*auto end_time = chrono::high_resolution_clock::now();
  75.     chrono::duration<double> duration = end_time - start_time;
  76.     cout << duration.count() << "\n";
  77.     cin.close();
  78.     cout.close();*/
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement