Time Limit: 5000MS   Memory Limit: 65535KB   64bit IO Format: %I64d & %I64u

Description

  N planets are connected by M bidirectional channels that allow instant transportation. It's always possible to travel between any two planets through these channels. 
  If we can isolate some planets from others by breaking only one channel , the channel is called a bridge of the transportation system. 
People don't like to be isolated. So they ask what's the minimal number of bridges they can have if they decide to build a new channel. 
  Note that there could be more than one channel between two planets. 

Input

  The input contains multiple cases. 
  Each case starts with two positive integers N and M , indicating the number of planets and the number of channels. 
  (2<=N<=200000, 1<=M<=1000000) 
  Next M lines each contains two positive integers A and B, indicating a channel between planet A and B in the system. Planets are numbered by 1..N. 
  A line with two integers '0' terminates the input.

Output

  For each case, output the minimal number of bridges after building a new channel in a line.

Sample Input

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

Sample Output

0

Source

 
在原图上任意加一条边,询问最少还剩下多少桥。
缩完点,找树直径,把直径两端连起来,就是最优策略。

HDU4612 Warm up的更多相关文章

  1. HDU-4612 Warm up,tarjan求桥缩点再求树的直径!注意重边

    Warm up 虽然网上题解这么多,感觉写下来并不是跟别人竞争访问量的,而是证明自己从前努力过,以后回头复习参考! 题意:n个点由m条无向边连接,求加一条边后桥的最少数量. 思路:如标题,tarjan ...

  2. HDU4612 Warm up —— 边双联通分量 + 重边 + 缩点 + 树上最长路

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4612 Warm up Time Limit: 10000/5000 MS (Java/Ot ...

  3. HDU4612 Warm up 边双连通分量&&桥&&树直径

    题目的意思很简单,给你一个已经连通的无向图,我们知道,图上不同的边连通分量之间有一定数量的桥,题目要求的就是要你再在这个图上加一条边,使得图的桥数目减到最少. 首先要做的就是找出桥,以及每个点所各自代 ...

  4. HDU4612 Warm up 边双(重边)缩点+树的直径

    题意:一个连通无向图,问你增加一条边后,让原图桥边最少 分析:先边双缩点,因为连通,所以消环变树,每一个树边都是桥,现在让你增加一条边,让桥变少(即形成环) 所以我们选择一条树上最长的路径,连接两端, ...

  5. HDU-4612 Warm up 边双连通分量+缩点+最长链

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 简单图论题,先求图的边双连通分量,注意,此题有重边(admin还逗比的说没有重边),在用targ ...

  6. HDU4612(Warm up)2013多校2-图的边双连通问题(Tarjan算法+树形DP)

    /** 题目大意: 给你一个无向连通图,问加上一条边后得到的图的最少的割边数; 算法思想: 图的边双连通Tarjan算法+树形DP; 即通过Tarjan算法对边双连通缩图,构成一棵树,然后用树形DP求 ...

  7. hdu4612 Warm up 缩点+树的直径

    题意抽象后为:给定一个无向图 问添加一条边的情况下最少能有多少个桥. 桥的定义:删除该边后原图变为多个连通块. 数据规模:点数N(2<=N<=200000),边数M(1<=M< ...

  8. hdu4612 Warm up[边双连通分量缩点+树的直径]

    给你一个连通图,你可以任意加一条边,最小化桥的数目. 添加一条边,发现在边双内是不会减少桥的.只有在边双与边双之间加边才有效.于是,跑一遍边双并缩点,然后就变成一棵树,这样要加一条非树边,路径上的点( ...

  9. tarjan算法求缩点+树形DP求直径

    hdu4612 Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

随机推荐

  1. topshelf包装redis为windows服务

    topshelf包装redis为windows服务 Redis服务端目前用的是控制台程序运行,部署的时候能作为windows服务后台运行感觉更好.找到一篇文章Running Redis as a Wi ...

  2. 从炉石传说的一个自杀OTK说起

    OTK就是one turn kill,不过这次我们要谈的OTK是自杀,对就是自己把自己给OTK了. 其实程序没有任何错误,只是恰巧碰上了这么个死循环. ps:文章最后有代码git地址 发动条件及效果: ...

  3. HBase初探

    string hbaseCluster = "https://charju.azurehdinsight.net"; string hadoopUsername = "账 ...

  4. 【转】Java 项目UML反向工程转化工具

    原文链接:http://www.cnblogs.com/bakari/p/3561207.html 今天在看一个模拟器的源码,一个包里有多个类,一个类里又有多个属性和方法,如果按顺序看下来,不仅不能对 ...

  5. hibernate 3.3.2GA版的下载

    网上马士兵老师采用的hibernate教程所使用的jar包便是hibernate 3.3.2GA,下载连接如下: http://download.csdn.net/detail/foreversile ...

  6. 68 id -显示用户的id

    Linux id命令用于显示用户的ID,以及所属群组的ID. id会显示用户以及所属群组的实际与有效ID.若两个ID相同,则仅显示实际ID.若仅指定用户名称,则显示目前用户的ID. 语法 id [-g ...

  7. kill 根据PID终止进程

    根据PID终止进程 kill [option] PID-list kill 通过向一个或多个进程发送信号来终止进程.除超级用户外,只有进程的所有者才可以对进程执行kill 参数 PID-list为ki ...

  8. 腾讯云CentOS 安装MediaWiki

    参考 : https://www.digitalocean.com/community/tutorials/how-to-install-mediawiki-on-centos-7 //安装好很多次终 ...

  9. oracle判断字段是否存在语句

    declare v_cnt number; begin select count(*) into v_cnt from dba_tab_columns where table_name='T_IDC_ ...

  10. ubuntu14.04 安装配置JDK1.7

    1,下载jdk-7u45-linux-x64.tar.gz 网址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downlo ...