Given an undirected graph, it is required to set some vertices as egress. After deleting any vertex in the graph, all the remaining vertices are connected to at least one egress to obtain the minimum number of egress and the number of minimum egress solutions.
First, we can see that the cut point is Tarjan.
First, suppose we scale down all vertices. Then we can get a tree and then we will find
The leaf node (which contains only one cut point and double point) must be created because if the leaf node is not created, it will end up as soon as the cut point is burst.
Non-leaf nodes (DOT pairs with two or more cut points) do not need to be created because even if one cut point is cracked, you can go to one leaf node along the other cut point.
Another case is that the entire Unicom block is a dot pair (that is, a dot pair without a cut point). In this case, we will discuss the size of the dot pair.
If there is only one vertex, the data must be created and there is no card for this vertex. So I didn't write it (in fact, I forgot to write it and then paid it back)
If there are two or more vertices, you need to create two, one, and the other.
Solution number is the principle of multiplication. Note that the exit of the leaf node cannot be built on the cut point.
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define M 1010using namespace std;typedef long long ll;struct abcd{int to,next;}table[M];int head[M],tot=1;int n,m,cases,ans1;long long ans2;int dpt[M],low[M],cnt,belong[M],stack[M],top;inline void Initialize(){memset(head,0,sizeof head);memset(dpt,0,sizeof dpt);memset(belong,0,sizeof belong);tot=1;n=0;ans1=0;ans2=1;}void Add(int x,int y){table[++tot].to=y;table[tot].next=head[x];head[x]=tot;}void Tarjan(int x){int i;dpt[x]=low[x]=++cnt;for(i=head[x];i;i=table[i].next){int y=table[i].to;if(dpt[y])low[x]=min(low[x],dpt[y]);else{Tarjan(y);low[x]=min(low[x],low[y]);if(low[y]>=dpt[x])belong[x]++;}}}void _Tarjan(int x){int i;dpt[x]=low[x]=++cnt;stack[++top]=x;for(i=head[x];i;i=table[i].next){int y=table[i].to;if(dpt[y])low[x]=min(low[x],dpt[y]);else{_Tarjan(y);low[x]=min(low[x],low[y]);if(low[y]>=dpt[x]){int t,temp=0,size=0;do{t=stack[top--];if(belong[t]>=2)++temp;++size;}while(t!=x);stack[++top]=x;if(!temp)ans1+=2,ans2*=size*(size-1)/2;else if(temp==1)ans1++,ans2*=size-1;}}}}int main(){//freopen("2730.in","r",stdin);int i,x,y;while(scanf("%d",&m),m){Initialize();for(i=1;i<=m;i++){scanf("%d%d",&x,&y);n=max(n,x);n=max(n,y);Add(x,y);Add(y,x);}for(i=1;i<=n;i++)if(!dpt[i])Tarjan(i);elsebelong[i]++;memset(dpt,0,sizeof dpt);for(i=1;i<=n;i++)if(!dpt[i])_Tarjan(i);cout<<"Case "<<++cases<<": ";cout<<ans1<<' '<<ans2<<endl;}}
Bzoj 2730 hnoi2012 mine construction Tarjan