Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define all(x) (x).begin(),(x).end()
- const int N = 30005;
- vector<int> adj[N];
- int num[N], low[N];
- int id = 0;
- vector<int> s;
- vector<vector<int>> res;
- void chmin(int &a, int b) {
- if (a > b) a = b;
- }
- void dfs(int i, int p) {
- if (!adj[i].size()) {
- res.push_back({i});
- return;
- }
- num[i] = low[i] = ++id;
- for (auto& j : adj[i]) {
- if (num[j]) {
- chmin(low[i], num[j]);
- }
- else {
- s.push_back(i);
- dfs(j, i);
- chmin(low[i], low[j]);
- if (low[j] == num[i]) {
- vector<int> bicon;
- int u;
- do {
- u = s.back();
- s.pop_back();
- bicon.push_back(u);
- } while (u != i);
- res.push_back(bicon);
- }
- }
- }
- s.push_back(i);
- }
- signed main() {
- // freopen("in" , "r", stdin );
- cin.tie(0)->sync_with_stdio(0);
- int n, m; cin >> n >> m;
- for (int i = 1; i <= m; i++) {
- int u, v; cin >> u >> v;
- adj[u].push_back(v);
- adj[v].push_back(u);
- }
- for (int i = 1; i <= n; i++) {
- if (!num[i]) dfs(i, -1);
- }
- // cout << res.size() << '\n';
- int ans = 0;
- for (auto& i : res) {
- sort(all(i));
- i.resize(unique(all(i)) - i.begin());
- // for (auto& j : i) cout << j << ' ';
- // cout << '\n';
- ans = max(ans, (int) i.size());
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement