/*
Tarjan求割点
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#define maxn 10010
using namespace std;
int n,m,num,head[maxn],low[maxn],dfn[maxn],f[maxn],father[maxn];
int point[maxn],topt,sum;
struct node{
int v,pre;
}e[maxn*];
stack<int>s;
int init(){
int x=;char s=getchar();
while(s<''||s>'')s=getchar();
while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
return x;
}
void Clear(){
memset(head,-,sizeof(head));
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(f,,sizeof(f));
memset(point,,sizeof(point));
num=topt=sum=;
while(!s.empty())s.pop();
}
void Add(int from,int to){
e[num].v=to;
e[num].pre=head[from];
head[from]=num++;
}
void Tarjan(int x,int fa,int E){
father[x]=fa;
dfn[x]=low[x]=++topt;
f[x]=;s.push(x);
int sc=;
for(int i=head[x];i!=-;i=e[i].pre){
int v=e[i].v;
if(i==(E^))continue;
if(dfn[v]==){
sc++;
Tarjan(v,x,i);low[x]=min(low[x],low[v]);
if(low[v]>=dfn[x])point[x]++;
}
else if(f[v])low[x]=min(low[x],dfn[v]);
}
if(fa<&&sc==)point[x]=;
if(low[x]==dfn[x]){
while(s.top()!=x){
f[s.top()]=;s.pop();
}
f[s.top()]=;s.pop();
}
}
void Init(){
for(int i=;i<=m;i++){
int u,v;
u=init();v=init();
u++;v++;
Add(u,v);Add(v,u);
}
for(int i=;i<=n;i++)
if(dfn[i]==){
sum++;Tarjan(i,-,-);
}
}
void Solve(){
int mxx=-;
for(int u=;u<=n;u++){
if(father[u]==-){
point[u]--;
}
mxx=max(mxx,point[u]);
}
printf("%d\n",sum+mxx);
}
int main()
{
while(){
n=init();m=init();
if(n==&&m==)break;
Clear();
Init();
Solve();
}
}

poj 2117 Electricity的更多相关文章

  1. POJ 2117 Electricity(割点求连通分量)

    http://poj.org/problem?id=2117 题意:求删除图中任意一个顶点后的最大连通分量数. 思路: 求出每个割点对应的连通分量数,注意这道题目中图可能是不连通的. 这道题目我wa了 ...

  2. POJ 2117 Electricity 双联通分量 割点

    http://poj.org/problem?id=2117 这个妹妹我竟然到现在才见过,我真是太菜了~~~ 求去掉一个点后图中最多有多少个连通块.(原图可以本身就有多个连通块) 首先设点i去掉后它的 ...

  3. poj 2117 Electricity(tarjan求割点删掉之后的连通块数)

    题目链接:http://poj.org/problem?id=2117 题意:求删除一个点后,图中最多有多少个连通块. 题解:就是找一下割点,根节点的割点删掉后增加son-1(son为子树个数),非根 ...

  4. poj 2117 Electricity【点双连通求删除点后最多的bcc数】

    Electricity Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4727   Accepted: 1561 Descr ...

  5. POJ—— 2117 Electricity

    Electricity Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5620   Accepted: 1838 Descr ...

  6. Electricity POJ - 2117 + SPF POJ - 1523 去除割点后求强连通分量个数问题

    Electricity POJ - 2117 题目描述 Blackouts and Dark Nights (also known as ACM++) is a company that provid ...

  7. POJ 2117 (割点+连通分量)

    题目链接: http://poj.org/problem?id=2117 题目大意:在一个非连通图中,求一个切除图中任意一个割点方案,使得图中连通分量数最大. 解题思路: 一个大陷阱,m可以等于0,这 ...

  8. 【POJ】2117 Electricity

    无向图求割点和连通块. /* POJ2117 */ #include <iostream> #include <vector> #include <algorithm&g ...

  9. poj 2117(割点的应用)

    题目链接:http://poj.org/problem?id=2117 思路:题目的意思是要求对于给定的无向图,删除某个顶点后,求最大的连通分量数.显然我们只有删掉割点后,连通分支数才会增加,因此我们 ...

随机推荐

  1. Python中几种数据结构的整理,列表、字典、元组、集合

    列表:shoplist = ['apple', 'mango', 'carrot', 'banana']字典:di = {'a':123,'b':'something'}集合:jihe = {'app ...

  2. Ferry Loading||

    uva10440:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...

  3. angularjs学习总结(~~很详细的教程)

    1 前言 前端技术的发展是如此之快,各种优秀技术.优秀框架的出现简直让人目不暇接,紧跟时代潮流,学习掌握新知识自然是不敢怠慢. AngularJS是google在维护,其在国外已经十分火热,可是国内的 ...

  4. 3.Repeater 绑定数据例子

    此例子绑定的数据源为微软在mssql2000中提供的Northwind数据库中的表Categories. 以下为设计步骤: 在C# 中连接数据库.如下图: 在项目中添加新建项,建立一个数据集,并把Ca ...

  5. Linux 多线程调试(内存占用、死循环、CPU占用率高……)

    文章出处:http://www.cnblogs.com/cy568searchx/archive/2013/10/28/3391790.html 你的软件在某个时刻停止服务,CPU占用达到100%+, ...

  6. linux(ubuntu)下分区和格式化sd卡

    我的手机sd卡需要分成两个分区,在windowxp下面死活搞不成.主要的问题是,window只认识sd卡的第一个分区.有人用修改驱动程序,让windows把sd卡认成日立的microdisk,分区和格 ...

  7. Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. 关于Linux

    这是一个2B让我写的关于Linux的一点东西. 其实我对Linux一直都是持有一种很尊敬的态度,作为一个非商业性的操作系统,能够成长成这样简直是不可思议,有一种Dota在游戏界的感觉,很让人佩服.但是 ...

  9. 手机app

    手机app是什么? 由于iPhone.三星等智能手机的逐步流行和广泛普及,手机app这个词语开始频繁的出现在广大手机网民的视线中.也许你们还不知道什么是手机app,但你一定下载过手机app,你的手机里 ...

  10. pygame学习资料

    pygame下载地址: https://bitbucket.org/pygame/pygame/downloads 12岁的少年教你用Python做小游戏 Beginning Game Program ...