POJ—— 2117 Electricity
| Time Limit: 5000MS | Memory Limit: 65536K | |
| Total Submissions: 5620 | Accepted: 1838 |
Description
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).
Input
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.
Output
Sample Input
3 3 0 1 0 2 2 1 4 2 0 1 2 3 3 1 1 0 0 0
Sample Output
1 2 2
Source
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define N 101000
using namespace std;
int n,m,x,y,s,tot,ans,son,tim,maxn,root;
int dfn[N],low[N],head[N],cut[N],cut_edge[N];
struct Edge
{
int to,from,next;
}edge[N];
int add(int x,int y)
{
tot++;
edge[tot].to=y;
edge[tot].next=head[x];
head[x]=tot;
}
int read()
{
,f=; char ch=getchar();
; ch=getchar();}
+ch-'; ch=getchar();}
return x*f;
}
int tarjan(int now,int pre)
{
dfn[now]=low[now]=++tim;
; bool boo=false;
for(int i=head[now];i;i=edge[i].next)
{
int t=edge[i].to;
)==pre) continue;
if(!dfn[t])
{
tarjan(t,i);
if(now==root) son++;
else
{
low[now]=min(low[now],low[t]);
if(dfn[now]<=low[t]) cut[now]++;
]=true;
}
}
else low[now]=min(low[now],dfn[t]);
}
}
int main()
{
)
{
n=read(),m=read();
&&m==) break;
) {printf(); continue;}
tot=,ans=,maxn=;tim=;
memset(cut,,sizeof(cut));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(head,,sizeof(head));
;i<=m;i++)
x=read(),y=read(),add(x+,y+),add(y+,x+);
;i<=n;i++)
{
if(!dfn[i])
{
root=i;son=;
tarjan(root,);
cut[root]=son-;
ans++;
}
maxn=max(cut[i],maxn);
}
printf("%d\n",ans+maxn);
}
;
}
POJ—— 2117 Electricity的更多相关文章
- POJ 2117 Electricity(割点求连通分量)
http://poj.org/problem?id=2117 题意:求删除图中任意一个顶点后的最大连通分量数. 思路: 求出每个割点对应的连通分量数,注意这道题目中图可能是不连通的. 这道题目我wa了 ...
- POJ 2117 Electricity 双联通分量 割点
http://poj.org/problem?id=2117 这个妹妹我竟然到现在才见过,我真是太菜了~~~ 求去掉一个点后图中最多有多少个连通块.(原图可以本身就有多个连通块) 首先设点i去掉后它的 ...
- poj 2117 Electricity(tarjan求割点删掉之后的连通块数)
题目链接:http://poj.org/problem?id=2117 题意:求删除一个点后,图中最多有多少个连通块. 题解:就是找一下割点,根节点的割点删掉后增加son-1(son为子树个数),非根 ...
- poj 2117 Electricity【点双连通求删除点后最多的bcc数】
Electricity Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4727 Accepted: 1561 Descr ...
- poj 2117 Electricity
/* Tarjan求割点 */ #include<iostream> #include<cstdio> #include<cstring> #include< ...
- Electricity POJ - 2117 + SPF POJ - 1523 去除割点后求强连通分量个数问题
Electricity POJ - 2117 题目描述 Blackouts and Dark Nights (also known as ACM++) is a company that provid ...
- POJ 2117 (割点+连通分量)
题目链接: http://poj.org/problem?id=2117 题目大意:在一个非连通图中,求一个切除图中任意一个割点方案,使得图中连通分量数最大. 解题思路: 一个大陷阱,m可以等于0,这 ...
- 【POJ】2117 Electricity
无向图求割点和连通块. /* POJ2117 */ #include <iostream> #include <vector> #include <algorithm&g ...
- poj 2117(割点的应用)
题目链接:http://poj.org/problem?id=2117 思路:题目的意思是要求对于给定的无向图,删除某个顶点后,求最大的连通分量数.显然我们只有删掉割点后,连通分支数才会增加,因此我们 ...
随机推荐
- Java文件上传(基础性)
/** * * 上传文件 * */ public class FileUploadServlet2 extends HttpServlet { protected void doGet(HttpSer ...
- (七)Mybatis总结之注解开发
请移步到 https://www.cnblogs.com/lxnlxn/p/5996707.html
- php debug/phpstorm调试
apache+phpstorm调试php代码,修改php.ini配置文件开启调试,没有以下代码加上即可, [XDebug]zend_extension="C:\php\php-7.0.12- ...
- LoadRunner 11中Record无法自动生成脚本——解决办法
[问题描述] 安装loadRunner 11, 使用IE为默认浏览器,打开一个页面进行脚本录制:录制完成后,无法生成脚本. [问题现象] 控制台输出如下: ****** Start Log Messa ...
- 微信小程序组件解读和分析:十一、label标签
label标签组件说明: label标签,与html的label标签基本一样.label 元素不会向用户呈现任何特殊效果.不过,它为鼠标用户改进了可用性.如果您在 label 元素内点击文本,就会触发 ...
- [转] 以超级管理员身份运行bat
(转自:以超级管理员身份运行bat - lishirong 原文日期:2013.07.04) 废话不多说,直接上代码: -------------------------------------- ...
- sqlalchemy ORM进阶- 批量插入数据
参考: https://www.jb51.net/article/49789.htm https://blog.csdn.net/littlely_ll/article/details/8270687 ...
- bat2exe 就是这么简单 白研究半天VC++了
bat2exe 就是这么简单 白研究半天VC++了 结果:bat2exe编译的执行文件会被杀毒软件查杀.
- TCP/IP 协议分层
协议分层 可能大家对OSI七层模型并不陌生,它将网络协议很细致地从逻辑上分为了7层.但是实际运用中并不是按七层模型,一般大家都只使用5层模型.如下: 物理层:一般包括物理媒介,电信号,光信号等,主要对 ...
- CAD使用DeleteXData删除数据(com接口)
主要用到函数说明: MxDrawEntity::DeleteXData 删除扩展数据,详细说明如下: 参数 说明 pzsAppName 删除的扩展数据名称,如果为空,删除所有扩展数据 c#代码实现如下 ...