COGS8. 备用交换机
题目大意:给这个点破坏后,会造成某两点不连通的点。
题解:Tarjian求割点
求割点
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstring> #define maxn 1200 using namespace std; int n,x,y,sumedge,ans,root,tim; int low[maxn],dfn[maxn],head[maxn],iscut[maxn]; struct Edge{ int x,y,nxt; Edge(int x=0,int y=0,int nxt=0): x(x),y(y),nxt(nxt){} }edge[maxn<<1]; void add(int x,int y){ edge[++sumedge]=Edge(x,y,head[x]); head[x]=sumedge; } void Tarjian(int x,int fa){ int cnt=0;low[x]=dfn[x]=++tim; for(int i=head[x];i;i=edge[i].nxt){ int v=edge[i].y; if(v==fa)continue; if(dfn[v]==0){ cnt++;Tarjian(v,x); low[x]=min(low[x],low[v]); if(low[v]>=dfn[x]&&x!=root&&iscut[x]==0)iscut[x]=1,ans++; if(x==root&&cnt>=2&&iscut[x]==0)iscut[x]=1,ans++; }else low[x]=min(low[x],dfn[v]); } } int main(){ freopen("gd.in","r",stdin); freopen("gd.out","w",stdout); scanf("%d",&n); while(scanf("%d%d",&x,&y)!=EOF){ add(x,y);add(y,x); } for(int i=1;i<=n;i++) if(!dfn[i])root=i,Tarjian(i,i); printf("%d\n",ans); for(int i=1;i<=n;i++) if(iscut[i]) printf("%d\n",i); fclose(stdin);fclose(stdout); return 0; }