HDU 4587 two nodes (dual connection cut point application)
Question: N points (0 ~ N-1), M undirected edges, and ask the maximum number of connected parts after removing the two points.
First, remove a vertex to find each cut point, in the dfs process, find out how many connected parts are removed from the cut point (Change iscut [u] = true to iscut [u] ++ ),
In this way, you can find the most connected parts for the second time.
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define M 5005int pre[M],dfs_clock,iscut[M],low[M],bcc_cnt,bccno[M];vector
G[M],bcc[M];struct Edge{ int from,to;}edge[M*2];int edge_num,head[M];void add_edge(int u,int v){ edge[edge_num].from=v; edge[edge_num].to=head[u]; head[u]=edge_num++;}int del;int dfs(int u,int fa){ int lowu=pre[u]=++dfs_clock; for(int i=head[u];i!=-1;i=edge[i].to) { int v=edge[i].from; if(v==del) continue; if(!pre[v]) { int lowv=dfs(v,u); lowu=min(lowv,lowu); if(lowv>=pre[u]) iscut[u]++; } else if(pre[v]