56642023-09-05 00:23:25TomaSajtKaktuszgráfcpp17Wrong answer 0/504ms5184 KiB
#include <bits/stdc++.h>
using namespace std;

vector<vector<array<int, 2>>> g;
vector<int> l, d;
int ts = 0;
stack<int> st;
vector<int> comp_sizes;

// components are separated by cutting vertices
void make_comps(int u, int par_ei) {
  cout << "hey" << endl;
  d[u] = l[u] = ++ts;
  int ch = 0;
  for (auto& [v, ei] : g[u]) {
    if (ei == par_ei) continue;  // case: tree-edge, from the other direction
    if (d[v] > d[u]) continue;   // case: back-edge, from the other direction
    st.push(ei);
    if (d[v] != 0) {
      // case: (u,v) is back-edge
      l[u] = min(l[u], d[v]);
      continue;
    }
    // case: (u,v) is tree-edge
    ch++;
    make_comps(v, ei);
    l[u] = min(l[u], l[v]);

    if ((par_ei == -1 && ch > 1) || (l[v] >= d[u])) {
      // case: u is a cutting vertex
      comp_sizes.push_back(0);
      while (st.top() != ei) {
        comp_sizes.back()++;
        st.pop();
      }
      comp_sizes.back()++;
      st.pop();
    }
  }
}

int main() {
  cin.tie(0), ios::sync_with_stdio(0);

  int n, m;
  cin >> n >> m;

  g.resize(n + 1);
  for (int ei = 0; ei < m; ei++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back({v, ei});
    g[v].push_back({u, ei});
  }

  l.resize(n + 1), d.resize(n + 1);
  make_comps(1, -1);
  comp_sizes.back() += st.size();

  cout << *max_element(comp_sizes.begin(), comp_sizes.end());
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1956 KiB
2Wrong answer0/04ms2256 KiB
3Wrong answer0/24ms2452 KiB
4Wrong answer0/24ms2596 KiB
5Wrong answer0/24ms2840 KiB
6Wrong answer0/24ms2964 KiB
7Wrong answer0/24ms3428 KiB
8Wrong answer0/24ms3492 KiB
9Wrong answer0/24ms3464 KiB
10Wrong answer0/24ms3564 KiB
11Wrong answer0/24ms3784 KiB
12Wrong answer0/24ms3776 KiB
13Wrong answer0/24ms3916 KiB
14Wrong answer0/24ms3808 KiB
15Wrong answer0/24ms4092 KiB
16Wrong answer0/24ms4108 KiB
17Wrong answer0/24ms4120 KiB
18Wrong answer0/24ms4256 KiB
19Wrong answer0/34ms4404 KiB
20Wrong answer0/34ms4552 KiB
21Wrong answer0/34ms4664 KiB
22Wrong answer0/34ms4928 KiB
23Wrong answer0/34ms4904 KiB
24Wrong answer0/34ms5184 KiB