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. CSS3 按钮特效(一)

    1. 实例 2.HTML 代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  2. iOS programming UITableView and UITableViewController

    iOS programming  UITableView and UITableViewController A UITableView displays a single column of dat ...

  3. table鼠标滑过变颜色

    table鼠标滑过变颜色 添加 table tr:hover{background-color: #eee;} 设置鼠标滑过行背景变色,重新刷新浏览器页面.  一般设置灰色,eee

  4. 关于AMAZON SES设置的一些要点

    1.首先要有一个企业邮箱,如果没有可以去腾讯(http://exmail.qq.com/onlinesell/intro)申请一个,网易也有,不过解析几次搞了两天都是未通过,腾讯几分钟就好了 企业邮箱 ...

  5. 梅沙教育APP简单分析-版本:iOS v1.2.21-Nathaneko-佳钦

    梅沙教育APP简单分析 时间:2017年6月6日 版本:iOS v1.2.21 分析人:Nathaneko-佳钦 备注:仅仅是个人一些简单的分析与见解,非正式产品分析报告,未体验购买相关功能,可能存在 ...

  6. web pack 生成本地dist后 本地可以访问 路径由/ 改 ./

    config / index.js 里面将 / 改成 ./ 有两个 都改了 反正管用 然后npm run build 如果涉及到字体 css里面不会改 需要手工改成 ../../ 反正一般用到字体也不 ...

  7. Java 类执行顺序

    1.如果父类有静态成员赋值或者静态初始化块,执行静态成员赋值和静态初始化块2.如果类有静态成员赋值或者静态初始化块,执行静态成员赋值和静态初始化块3.将类的成员赋予初值(原始类型的成员的值为规定值,例 ...

  8. CS2QS

    inline QString MotorCS2QS(CString cs) { return QString::fromWCharArray((LPCTSTR)cs, cs.GetLength()); ...

  9. CAD绘制固定圆形云线标注(网页吧)

    js中实现代码说明: function DoCloudCircleCommentFix() { var comment = mxOcx.NewEntity("IMxDrawComment&q ...

  10. MySQL和Oracle的比较

    可以从以下几个方面来进行比较: (1) 对事务的提交    MySQL默认是自动提交,而Oracle默认不自动提交,需要用户手动提交,需要在写commit;指令或者点击commit按钮(2) 分页查询 ...