描述

Blackouts and Dark Nights (also known as ACM++) is a company that provides electricity. The company owns several power plants, each of them supplying a small area that surrounds it. This organization brings a lot of problems - it often happens that there is not enough power in one area, while there is a large surplus in the rest of the country.

ACM++
has therefore decided to connect the networks of some of the plants
together. At least in the first stage, there is no need to connect all
plants to a single network, but on the other hand it may pay up to
create redundant connections on critical places - i.e. the network may
contain cycles. Various plans for the connections were proposed, and the
complicated phase of evaluation of them has begun.

One of the
criteria that has to be taken into account is the reliability of the
created network. To evaluate it, we assume that the worst event that can
happen is a malfunction in one of the joining points at the power
plants, which might cause the network to split into several parts. While
each of these parts could still work, each of them would have to cope
with the problems, so it is essential to minimize the number of parts
into which the network will split due to removal of one of the joining
points.

Your task is to write a software that would help
evaluating this risk. Your program is given a description of the
network, and it should determine the maximum number of non-connected
parts from that the network may consist after removal of one of the
joining points (not counting the removed joining point itself).

输入

The input consists of several instances.

The
first line of each instance contains two integers 1 <= P <= 10
000 and C >= 0 separated by a single space. P is the number of power
plants. The power plants have assigned integers between 0 and P - 1. C
is the number of connections. The following C lines of the instance
describe the connections. Each of the lines contains two integers 0
<= p1, p2 < P separated by a single space, meaning that plants
with numbers p1 and p2 are connected. Each connection is described
exactly once and there is at most one connection between every two
plants.

The instances follow each other immediately, without any separator. The input is terminated by a line containing two zeros.

输出

The
output consists of several lines. The i-th line of the output
corresponds to the i-th input instance. Each line of the output consists
of a single integer C. C is the maximum number of the connected parts
of the network that can be obtained by removing one of the joining
points at power plants in the instance.

样例输入

3 3
0 1
0 2
2 1
4 2
0 1
2 3
3 1
1 0
0 0

样例输出

1
2
2

题意

有N个点编号0-N-1,让你去掉一个点,最多剩下的连通图数

题解

去掉一个点使得连通数尽可能多,可以想到去掉的是割点

如果low[v]>=low[u]   cut[u]=true说明u是割点

如果改成cut[u]++,说明去掉u点会多形成cut[u]个连通图

如果u是根节点

1.cut[u]=0 说明u为孤立点 则去掉后连通数少1

2.cut[u]=1 说明u只有一个儿子 则去掉后连通数不变

3.cut[u]>=2 说明u有>=2个儿子 则去掉后连通数多cut[u]-1

代码

 #include<bits/stdc++.h>
using namespace std; const int maxn=1e4+; vector< vector<int> >G(maxn);
int dfn[maxn],low[maxn],cut[maxn];
int n,m,ans,tot; void tarjan(int u,int fa)
{
dfn[u]=low[u]=++tot;
for(int i=;i<G[u].size();i++)
{
int v=G[u][i];
if(v==fa)continue;
if(!dfn[v])
{
tarjan(v,u);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u])cut[u]++;
}
low[u]=min(low[u],dfn[v]);
}
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF,n||m)
{
ans=tot=;
for(int i=;i<n;i++)low[i]=dfn[i]=cut[i]=,G[i].clear();
for(int i=,u,v;i<m;i++)
{
scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
for(int i=;i<n;i++)
{
if(!dfn[i])
{
ans++;
tarjan(i,-);
cut[i]--;
}
}
printf("%d\n",ans+*max_element(cut,cut+n));
}
return ;
}

TZOJ 2546 Electricity(去掉割点后形成的最大连通图数)的更多相关文章

  1. 【UVA10765】Doves and bombs (BCC求割点后联通块数量)

    题目: 题意: 给了一个联通无向图,现在问去掉某个点,会让图变成几个联通块? 输出的按分出的从多到小,若相等,输出标号从小到大.输出M个. 分析: BCC求割点后联通块数量,Tarjan算法. 联通块 ...

  2. hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。

    题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...

  3. 黄聪:Dsicuz x2.5、X3、X3.2如何去掉域名后面的/forum.php

    Dsicuz x2.5去掉域名后面的/forum.php 1, 后台--全局--域名设置--应用域名--设置默认域名为访问域名就可以,如:www.xxxxx.com 上面2种方法都可以去掉域名后面的/ ...

  4. PHP去掉转义后字符串中的反斜杠\函数stripslashes

    addslashes函数主要是在字符串中添加反斜杠对特殊字符进行转义,stripslashes则是去掉转义后字符串中的反斜杠\,比如当你提交一段 json数据到PHP端的时候可能会遇到json字符串中 ...

  5. (转载)PHP去掉转义后字符串中的反斜杠\函数stripslashes

    (转载)http://www.beijibear.com/index.php?aid=182 addslashes()函数主要是在字符串中添加反斜杠对特殊字符进行转义,stripslashes()则是 ...

  6. 黄聪:PHP去掉转义后字符串中的反斜杠\函数stripslashes

    addslashes函数主要是在字符串中添加反斜杠对特殊字符进行转义,stripslashes则是去掉转义后字符串中的反斜杠\,比如当你提交一段json数据到PHP端的时候可能会遇到json字符串中有 ...

  7. 利用神经网络进行网络流量识别——特征提取的方法是(1)直接原始报文提取前24字节,24个报文组成596像素图像CNN识别;或者直接去掉header后payload的前1024字节(2)传输报文的大小分布特征;也有加入时序结合LSTM后的CNN综合模型

    国外的文献汇总: <Network Traffic Classification via Neural Networks>使用的是全连接网络,传统机器学习特征工程的技术.top10特征如下 ...

  8. MySQL 分组后,统计记录条数

    分组后,统计记录条数: SELECT num,count(*) AS counts from test_a GROUP BY num; 查询结果如下: 对num去重后的数量的统计: SELECT co ...

  9. mysql中左连接后,最终的记录数大于左边表的记录分析

    如果B表符合条件的记录数大于1条,就会出现1:n的情况,这样left join后的结果,记录数会多于A表的记录数. 例如:member与member_login_log表的结构如下,member记录会 ...

随机推荐

  1. python_04 基本数据类型、数字、字符串、列表、元组、字典

    基本数据类型 所有的方法(函数)都带括号,且括号内没带等号的参数需传给它一个值,带等号的参数相当于有默认值 1.数字 int 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1 ...

  2. 排序NB三人组

    排序NB三人组 快速排序,堆排序,归并排序 1.快速排序 方法其实很简单:分别从初始序列“6  1  2 7  9  3  4  5 10  8”两端开始“探测”.先从右往左找一个小于6的数,再从左往 ...

  3. 配置maven访问nexus,配置项目pom.xml以发布maven项目到nexus中

    maven访问nexus有三种配置方法,分别为: 项目pom.xml,优先级最高: user的settings.xml,优先级中,未在pom.xml中配置repository标签,则使用这个配置: m ...

  4. java-部分精选面试题

    JVM的类加载机制是什么?有哪些实现方式? 类加载机制: 类的加载指的是将类的.class文件中的二进制数据读入到内存中,将其放在运行时数据区的方法去内,然后在堆区创建一个java.lang.Clas ...

  5. python使用xlrd 操作Excel读写

    此文章非本人 一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. 二.使用介绍 1.导入模块 i ...

  6. [PHP]更新中间关联表数据的两种思路

    ---------------------------------------------------------------------------------------------------- ...

  7. jQuery图片延迟加载插件:jquery.lazyload

    ----------------------------------------------------------------------------------------------- clas ...

  8. 7.final关键字.md

    1.final类型变量 定义:被final修饰的变量,一旦被赋初值后,则final类型变量的值就不能再改变. 1.1成员变量 final修饰的成员变量必须显式的赋初值. 赋值的位置: •类变量:静态初 ...

  9. 初级JS

    唐太宗  李世民  杀了大哥 和弟弟  登上的皇位    一个人当皇帝 排他性是指一种物品具有可以阻止其他人使用该物品的特性. 排他性思想: 在程序中但凡是遇到只让自己怎么样,不让别人怎么样的效果,都 ...

  10. centos FTP 用户指定目录禁用上级目录

    在默认配置下,本地用户登入FTP后可以使用cd命令切换到其他目录,这样会对系统带来安全隐患.可以通过以下三条配置文件来控制用户切换目录.chroot_list_enable=YES/NO(NO)设置是 ...