Advertisement
tuki2501

NETMAX.cpp

Dec 7th, 2020
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define all(x) (x).begin(),(x).end()
  5.  
  6. const int N = 30005;
  7.  
  8. vector<int> adj[N];
  9. int num[N], low[N];
  10. int id = 0;
  11. vector<int> s;
  12. vector<vector<int>> res;
  13.  
  14. void chmin(int &a, int b) {
  15.   if (a > b) a = b;
  16. }
  17.  
  18. void dfs(int i, int p) {
  19.   if (!adj[i].size()) {
  20.     res.push_back({i});
  21.     return;
  22.   }
  23.   num[i] = low[i] = ++id;
  24.   for (auto& j : adj[i]) {
  25.     if (num[j]) {
  26.       chmin(low[i], num[j]);
  27.     }
  28.     else {
  29.       s.push_back(i);
  30.       dfs(j, i);
  31.       chmin(low[i], low[j]);
  32.       if (low[j] == num[i]) {
  33.         vector<int> bicon;
  34.         int u;
  35.         do {
  36.           u = s.back();
  37.           s.pop_back();
  38.           bicon.push_back(u);
  39.         } while (u != i);
  40.         res.push_back(bicon);
  41.       }
  42.     }
  43.   }
  44.   s.push_back(i);
  45. }
  46.  
  47. signed main() {
  48.   // freopen("in" , "r", stdin );
  49.   cin.tie(0)->sync_with_stdio(0);
  50.   int n, m; cin >> n >> m;
  51.   for (int i = 1; i <= m; i++) {
  52.     int u, v; cin >> u >> v;
  53.     adj[u].push_back(v);
  54.     adj[v].push_back(u);
  55.   }
  56.   for (int i = 1; i <= n; i++) {
  57.     if (!num[i]) dfs(i, -1);
  58.   }
  59.   // cout << res.size() << '\n';
  60.   int ans = 0;
  61.   for (auto& i : res) {
  62.     sort(all(i));
  63.     i.resize(unique(all(i)) - i.begin());
  64.     // for (auto& j : i) cout << j << ' ';
  65.     // cout << '\n';
  66.     ans = max(ans, (int) i.size());
  67.   }
  68.   cout << ans << '\n';
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement