/*
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. 转 四大Java EE容器(Tomcat、JBoss、Resin、Glassfish)之简单比较

                                      现在流行的Java EE容器有很多:Tomcat.JBoss.Resin.Glassfish等等.下面对这四种Java EE容器进行 ...

  2. matplotlib.pyplot 绘图详解 matplotlib 安装

    apt-get install python-matplotlib 转载自: http://www.cnblogs.com/qianlifeng/archive/2012/02/13/2350086. ...

  3. cf B Three matrices

    #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ][] ...

  4. win平台下, 检测网络是否连接最好的办法

    [Delphi]检查URL是否有效的函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 function CheckUr ...

  5. Pots(bfs)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8266   Accepted: 3507   Special Judge D ...

  6. vijos1514天才的记忆

    P1514天才的记忆 背景 神仙飞啊飞 描述 从前有个人名叫W and N and B,他有着天才般的记忆力,他珍藏了许多许多的宝藏.在他离世之后留给后人一个难题(专门考验记忆力的啊!),如果谁能轻松 ...

  7. id有空格获取不到元素

  8. 数学(线性规划): ZJOI2013 防守战线

    偷懒用的线性规划. #include <iostream> #include <cstring> #include <cstdio> using namespace ...

  9. Simplify Path——LeetCode

    Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", ...

  10. Unable to load native-hadoop library解决思路

    最近试着搭建Hadoop,我使用的操作系统是Centos6.5,Hadoop版本是2.6.0. 在安装过程中总是出现:WARN util.NativeCodeLoader: Unable to loa ...