/*
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. php开发学习目录

    最近有个项目需要使用php,没办法学习吧 本文不适合没有任何语言的初学者,也不适合 php熟练者.只是个人工作中需要的总结 目录 一.环境安装 1.1 apache 简介安装使用等 1.2 php 5 ...

  2. STM32学习笔记——SPI串行通讯(向原子哥学习)

    一.SPI  简介 SPI是 Serial Peripheral interface 的缩写,就是串行外围设备接口.SPI 接口主要应用在  EEPROM, FLASH,实时时钟,AD 转换器,还有数 ...

  3. 首页重定位到mian.action上

    <body onload="top.location.href='<%=request.getContextPath()%>/main.action';">

  4. Struts2 Tomcat的配置

    1. 下载Struts2包,网站http://struts.apache.org/download.cgi#struts2315 2. 将struts-2.3.15-all.zip 包解压到本地 3. ...

  5. Ubiquitous Religions(并查集)

    Description There are so many different religions in the world today that it is difficult to keep tr ...

  6. Hibernate 配置详解(2)

    6) hibernate.session_factory_name: 配置一个JNDI名称,通过Configuration对象创建的SessionFactory会绑定到JNDI下该名称中.一般名字格式 ...

  7. ie中弹出框中元素的定位

    用selenium在ie8浏览器中定位一个弹出框时,直接用ie developer tools可能不一定能定位到,有一个解决的办法是直接在url后面加上#noHide,刷新后,然后再用ie devel ...

  8. 迷宫 maze

    1 #include <stdlib.h> #include <stdio.h> #define stackinitsize 50 #define stackincrement ...

  9. qemu kvm 虚拟化

    虚拟化: KVM是一个基于Linux内核的虚拟机,属于完全虚拟化.虚拟机监控的实现模型有两类:监控模型(Hypervisor)和宿主机模型(Host-based).由于监控模型需要进行处理器调度,还需 ...

  10. JAVA工程师面试总结

    HR面: 你为什么要离职?如果是公司层面的,公司为什么要这么做? 你的理想薪资?你觉得你有什么优势胜任你应聘的工作? 你的未来发展规划? BOSS面: 项目的东西,hibernate调优?使用了什么数 ...