#pragma once
#include"./graph-template.hpp"
#include"./lowlink.hpp"template<typenameG>structTwoEdgeConnectedComponents{constG&g;LowLink<G>low;vector<int>comp;intk;vector<vector<int>>groups,tree;TwoEdgeConnectedComponents(constG&g_):g(g_),low(g_),comp(g_.size(),-1),k(0){for(inti=0;i<(int)g.size();i++){if(comp[i]==-1)dfs(i,-1);}groups.resize(k);tree.resize(k);for(inti=0;i<(int)g.size();i++){groups[comp[i]].push_back(i);}for(auto&e:low.bridge){intu=comp[e.first],v=comp[e.second];tree[u].push_back(v);}};intoperator[](constint&k)const{returncomp[k];}voiddfs(inti,intp){if(p>=0&&low.ord[p]>=low.low[i])comp[i]=comp[p];elsecomp[i]=k++;for(auto&d:g[i]){if(comp[d]==-1)dfs(d,i);}}};
#line 2 "graph/two-edge-connected-components.hpp"
#line 2 "graph/graph-template.hpp"
template<typenameT>structedge{intsrc,to;Tcost;edge(int_to,T_cost):src(-1),to(_to),cost(_cost){}edge(int_src,int_to,T_cost):src(_src),to(_to),cost(_cost){}edge&operator=(constint&x){to=x;return*this;}operatorint()const{returnto;}};template<typenameT>usingEdges=vector<edge<T>>;template<typenameT>usingWeightedGraph=vector<Edges<T>>;usingUnweightedGraph=vector<vector<int>>;// Input of (Unweighted) GraphUnweightedGraphgraph(intN,intM=-1,boolis_directed=false,boolis_1origin=true){UnweightedGraphg(N);if(M==-1)M=N-1;for(int_=0;_<M;_++){intx,y;cin>>x>>y;if(is_1origin)x--,y--;g[x].push_back(y);if(!is_directed)g[y].push_back(x);}returng;}// Input of Weighted Graphtemplate<typenameT>WeightedGraph<T>wgraph(intN,intM=-1,boolis_directed=false,boolis_1origin=true){WeightedGraph<T>g(N);if(M==-1)M=N-1;for(int_=0;_<M;_++){intx,y;cin>>x>>y;Tc;cin>>c;if(is_1origin)x--,y--;g[x].emplace_back(x,y,c);if(!is_directed)g[y].emplace_back(y,x,c);}returng;}// Input of Edgestemplate<typenameT>Edges<T>esgraph([[maybe_unused]]intN,intM,intis_weighted=true,boolis_1origin=true){Edges<T>es;for(int_=0;_<M;_++){intx,y;cin>>x>>y;Tc;if(is_weighted)cin>>c;elsec=1;if(is_1origin)x--,y--;es.emplace_back(x,y,c);}returnes;}// Input of Adjacency Matrixtemplate<typenameT>vector<vector<T>>adjgraph(intN,intM,TINF,intis_weighted=true,boolis_directed=false,boolis_1origin=true){vector<vector<T>>d(N,vector<T>(N,INF));for(int_=0;_<M;_++){intx,y;cin>>x>>y;Tc;if(is_weighted)cin>>c;elsec=1;if(is_1origin)x--,y--;d[x][y]=c;if(!is_directed)d[y][x]=c;}returnd;}/**
* @brief グラフテンプレート
* @docs docs/graph/graph-template.md
*/#line 2 "graph/lowlink.hpp"
#include<vector>usingnamespacestd;#line 7 "graph/lowlink.hpp"
// bridge ... 橋 (辺 (u, v) が u < v となるように格納)// articulation point ... 関節点template<typenameG>structLowLink{constG&g;intN;vector<int>ord,low,articulation;vector<pair<int,int>>bridge;LowLink(constG&_g):g(_g),N(g.size()),ord(N,-1),low(N,-1){for(inti=0,k=0;i<N;i++){if(ord[i]==-1){k=dfs(i,k,-1);}}}intdfs(intidx,intk,intpar){low[idx]=(ord[idx]=k++);intcnt=0;boolarti=false,second=false;for(auto&to:g[idx]){if(ord[to]==-1){cnt++;k=dfs(to,k,idx);low[idx]=min(low[idx],low[to]);arti|=(par!=-1)&&(low[to]>=ord[idx]);if(ord[idx]<low[to]){bridge.emplace_back(minmax(idx,(int)to));}}elseif(to!=par||second){low[idx]=min(low[idx],ord[to]);}else{second=true;}}arti|=par==-1&&cnt>1;if(arti)articulation.push_back(idx);returnk;}};#line 5 "graph/two-edge-connected-components.hpp"
template<typenameG>structTwoEdgeConnectedComponents{constG&g;LowLink<G>low;vector<int>comp;intk;vector<vector<int>>groups,tree;TwoEdgeConnectedComponents(constG&g_):g(g_),low(g_),comp(g_.size(),-1),k(0){for(inti=0;i<(int)g.size();i++){if(comp[i]==-1)dfs(i,-1);}groups.resize(k);tree.resize(k);for(inti=0;i<(int)g.size();i++){groups[comp[i]].push_back(i);}for(auto&e:low.bridge){intu=comp[e.first],v=comp[e.second];tree[u].push_back(v);}};intoperator[](constint&k)const{returncomp[k];}voiddfs(inti,intp){if(p>=0&&low.ord[p]>=low.low[i])comp[i]=comp[p];elsecomp[i]=k++;for(auto&d:g[i]){if(comp[d]==-1)dfs(d,i);}}};