/*
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 Cookie学习

    <?php /* Cookie在计算机中保存的格式 用户名@网站地址[数字].txt Cookie在文件夹下,每个Cookie文件都是一个简单而又普通的文件件而不是程序,Cookie中的内容大多 ...

  2. python运维开发之路第一天

    一.python安装及环境变量配置 1.windows7安装python 1)下载地址:https://www.python.org/downloads/windows/ 如下图: 注意:下载,用代理 ...

  3. python django 自定义 装饰器

    # -*-coding:utf-8-*- __author__ = "GILANG (pleasurelong@foxmail.com)" """ d ...

  4. Ruby自学笔记(四)— 数组,Hash,正则表达式简介

    今天学习的是数组和Hash,数组在很多编程语言中都能常常用到. 数组: 数组是存储数据的一种容器,在Ruby中,数组中存储的数据可以是任何类型的数据:这和JAVA不同,在JAVA中,数组是存储同一类型 ...

  5. C++类:private、public、friend、protected的区别

           private和public的作用是让编译器帮你检查某些模块是否使用了他没权限使用的模块,也就是生成可执行代码的时候做权限检查.比如,公司里各个部门有自己私有的信息,财务部可以看所有员工 ...

  6. unix io 模型浅析

    POSIX中对同步IO和异步IO的规定: 同步IO操作:引起进程的阻塞直到IO操作完成,异步IO操作:IO操作不会引起进程阻塞 在UNIX下,有5中操作模型: 阻塞IO,非阻塞IO,IO复用,信号驱动 ...

  7. Android 安装过程中的问题

    Android  安装过程中的问题 上一篇我说到配置android环境,但是在具体的安装过程中,因为下载的软件或者方法不同,导致没有正确的结果,如果有一些错误的时候,可以试一试关闭eclipse软件, ...

  8. 牛逼的bootcss之buttons

    css源码 /*! @license * * Buttons * Copyright 2012-2014 Alex Wolfe and Rob Levin * * Licensed under the ...

  9. nginx 1.3.9/1.4.0 x86 Brute Force Remote Exploit

    测试方法: 本站提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负! #nginx 1.3.9/1.4.0 x86 brute force remote exploit # copyri ...

  10. hdu-1890-Robotic Sort splay区间翻转

    题意: 依次找第i大的数下标pos[i],然后将区间[i,pos[i]]翻转 分析: splay树区间翻转 // File Name: ACM/HDU/1890.cpp // Author: Zlbi ...