标签:
题意:给出一个无向图及边的关系,求割点个数
思路:无向图割点纯模版,不多说,这篇写的很好理解点这里
#include <vector> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const int maxn=110; vector<int>G[maxn]; int E[maxn],L[maxn],vis[maxn],cnt[maxn]; int k,kk; void dfs(int x){ k++;E[x]=k;L[x]=k;vis[x]=1; for(unsigned int i=0;i<G[x].size();i++){ int t=G[x][i]; if(!vis[t]){ dfs(t); L[x]=min(L[x],L[t]); if(L[t]>=E[x]&&x!=1) cnt[x]++; else if(x==1) kk++; }else L[x]=min(L[x],E[t]); } } int main(){ int n,a,b,c; while(scanf("%d",&n)!=-1){ if(n==0) break; for(int i=0;i<maxn;i++) G[i].clear(); memset(vis,0,sizeof(vis)); memset(cnt,0,sizeof(cnt)); while(scanf("%d",&a)!=-1){ if(a==0) break; while(getchar()!='\n'){ scanf("%d",&b); G[a].push_back(b); G[b].push_back(a); } } int ans=0; k=0;kk=0;dfs(1); if(kk>=2) ans++; for(int i=1;i<=n;i++){ if(cnt[i]>=1) ans++; } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://blog.csdn.net/dan__ge/article/details/51306299