Electricity
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 5620   Accepted: 1838

Description

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).

Input

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.

Output

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.

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的更多相关文章

  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

    /* Tarjan求割点 */ #include<iostream> #include<cstdio> #include<cstring> #include< ...

  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之java.sql.SQLException: ResultSet is from UPDATE. No Data.

    问题解释:java调用存储过程的时候,查询结果不能通过ResultSet来查询,需要通过CallableStatement来查询, 比如: ResultSet rs = callableStateme ...

  2. HttpWebRequest 以及WebRequest的使用

    1.WebRequest的发送数据以及接收数据 class Program { static void Main(string[] args) { //创建一个实例并发送请求 HttpWebReque ...

  3. 新浪qq登录

    一:到腾讯QQ互联上申请APPID和APPKEY.申请地址: http://connect.qq.com/ 如同,这里我们可以获取到需要跳转到的APPID和APPKEY.新浪微博的申请同理 二:在Th ...

  4. php判断是否引入某文件

    Code: /* 判断是否引入了公共文件demo.php */ $include_files = get_included_files(); $include_files_exist = 0 ; fo ...

  5. Python游戏开发入门

    Pygame简介与安装 1.Pygame安装 pip install pygame2.检测pygame是否安装成功 python -m pygame.examples.aliens Pygame最小开 ...

  6. oracle 时区

    select sysdate from dual;select systimestamp from dual;select localtimestamp from dual;select curren ...

  7. crontab 每月最后一天执行命令

    没有什么是解决不了的事情,如果有,只是我们的知识不够精通,学得不扎实 需求:有一个程序,需要在每个月的最后一天执行 例如:每个月的最后一天早上8:00 打印 dede 到  /tmp/test.txt ...

  8. NLog小记

    NLog安装: Install-Package NLog NLog配置: <?xml version="1.0" encoding="utf-8" ?&g ...

  9. 卸载钩子 UnhookWindowsHookEx

    The UnhookWindowsHookEx function removes a hook procedure installed in a hook chain by the SetWindow ...

  10. A10. JVM 对象

    [概述] 首先需要了解对象在内存中的存储布局,其次需要了解对对象的访问定位. [对象的内存布局] 在 HotSpot 虚拟机中,对象在内存中存储的布局可以分为 3 块区域:对象头(Header).实例 ...