This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub tko919/library
#define PROBLEM "https://judge.yosupo.jp/problem/two_edge_connected_components" #include "Template/template.hpp" #include "Graph/lowlink.hpp" int main(){ int n,m; cin>>n>>m; LowLink low(n); rep(_,0,m){ int x,y; cin>>x>>y; low.add_edge(x,y); } int ret=low.run(); vector g(ret,vector<int>()); rep(i,0,n)g[low.id[i]].push_back(i); cout<<ret<<'\n'; rep(i,0,g.size()){ cout<<g[i].size()<<' '; rep(j,0,g[i].size())cout<<g[i][j]<<(j==(int)g[i].size()-1?'\n':' '); } return 0; }
#line 1 "Verify/LC_two_edge_connected_components.test.cpp" #define PROBLEM "https://judge.yosupo.jp/problem/two_edge_connected_components" #line 1 "Template/template.hpp" #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b-1); i >= (int)(a); i--) #define ALL(v) (v).begin(), (v).end() #define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end()) #define SZ(v) (int)v.size() #define MIN(v) *min_element(ALL(v)) #define MAX(v) *max_element(ALL(v)) #define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin()) #define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin()) using uint = unsigned int; using ll = long long int; using ull = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T, typename U> T ceil(T x, U y) { assert(y != 0); if (y < 0) x = -x, y = -y; return (x > 0 ? (x + y - 1) / y : x / y); } template <typename T, typename U> T floor(T x, U y) { assert(y != 0); if (y < 0) x = -x, y = -y; return (x > 0 ? x / y : (x - y + 1) / y); } template <typename T> int popcnt(T x) { return __builtin_popcountll(x); } template <typename T> int topbit(T x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); } template <typename T> int lowbit(T x) { return (x == 0 ? -1 : __builtin_ctzll(x)); } #ifdef LOCAL #define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__) #else #define show(...) true #endif template <typename T> void _show(int i, T name) { cerr << '\n'; } template <typename T1, typename T2, typename... T3> void _show(int i, const T1 &a, const T2 &b, const T3 &...c) { for (; a[i] != ',' && a[i] != '\0'; i++) cerr << a[i]; cerr << ":" << b << " "; _show(i + 1, a, c...); } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "P(" << p.first << ", " << p.second << ")"; return os; } template <typename T, template <class> class C> ostream &operator<<(ostream &os, const C<T> &v) { os << "["; for (auto d : v) os << d << ", "; os << "]"; return os; } #line 2 "Graph/lowlink.hpp" struct LowLink{ const int n; vector<vector<int>> g; vector<int> used,ord,low,id,arti; LowLink(const int& _n=0):n(_n),g(n), used(n,0),ord(n,0),low(n,0),id(n,-1){ } void add_edge(int u,int v){ g[u].emplace_back(v); g[v].emplace_back(u); } void dfs(int v,int p,int& k){ used[v]=1; low[v]=ord[v]=k++; bool isarti=0; int cnt=0,sub=0; for(auto& to:g[v]){ if(to==p and (++sub)<=1)continue; if(!used[to]){ cnt++; dfs(to,v,k); chmin(low[v],low[to]); isarti|=(p>=0&&low[to]>=ord[v]); } else chmin(low[v],ord[to]); } isarti|=(p==-1&&cnt>1); if(isarti)arti.push_back(v); } void dfs2(int v,int p,int& k){ if(p!=-1 and ord[p]>=low[v])id[v]=id[p]; else id[v]=k++; for(auto& to:g[v])if(id[to]==-1)dfs2(to,v,k); } int run(){ int k=0; rep(i,0,n)if(!used[i])dfs(i,-1,k); k=0; rep(i,0,n)if(id[i]==-1)dfs2(i,-1,k); return k; } }; /** * @brief Lowlink */ #line 5 "Verify/LC_two_edge_connected_components.test.cpp" int main(){ int n,m; cin>>n>>m; LowLink low(n); rep(_,0,m){ int x,y; cin>>x>>y; low.add_edge(x,y); } int ret=low.run(); vector g(ret,vector<int>()); rep(i,0,n)g[low.id[i]].push_back(i); cout<<ret<<'\n'; rep(i,0,g.size()){ cout<<g[i].size()<<' '; rep(j,0,g[i].size())cout<<g[i][j]<<(j==(int)g[i].size()-1?'\n':' '); } return 0; }