标签:des style blog http color os java io for
3 3 0 1 0 2 2 1 4 2 0 1 2 3 3 1 1 0 0 0
1 2 2
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 10100; 18 int p,c; 19 int dfn[maxn],low[maxn],cut[maxn],vis[maxn],cnt; 20 vector<int>g[maxn]; 21 void tarjan(int u,int fa){ 22 dfn[u] = low[u] = ++cnt; 23 int son = 0; 24 vis[u] = 1; 25 for(int i = 0; i < g[u].size(); i++){ 26 if(!vis[g[u][i]]){ 27 tarjan(g[u][i],u); 28 son++; 29 low[u] = min(low[u],low[g[u][i]]); 30 if(fa == -1 && son > 1 || fa != -1 && dfn[u] <= low[g[u][i]]) cut[u]++; 31 }else if(g[u][i] != fa && vis[g[u][i]] == 1) low[u] = min(low[u],dfn[g[u][i]]); 32 } 33 vis[u] = 2; 34 } 35 int main() { 36 int i,u,v,ans,sum; 37 while(scanf("%d %d",&p,&c),p||c){ 38 if(!c){printf("%d\n",p-1);continue;} 39 for(i = 0; i <= p; i++){ 40 g[i].clear(); 41 vis[i] = 0; 42 dfn[i] = 0; 43 cut[i] = 0; 44 } 45 for(i = 0; i < c; i++){ 46 scanf("%d %d",&u,&v); 47 g[u].push_back(v); 48 g[v].push_back(u); 49 } 50 ans = sum = cnt = 0; 51 for(i = 0; i < p; i++){ 52 if(!vis[i]){tarjan(i,-1);sum++;} 53 if(cut[i] > ans) {ans = cut[i];} 54 } 55 printf("%d\n",ans+sum); 56 } 57 return 0; 58 }
标签:des style blog http color os java io for
原文地址:http://www.cnblogs.com/crackpotisback/p/3936903.html