Warm up

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1398    Accepted Submission(s): 320

Problem 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
 
Recommend
zhuyuanchen520
 

感想:

当时被爆栈爆到无语了。完全不知道为什么的爆栈。  这个题目讲的很清楚。。方法也很容易看出来,就是求无向图的桥的问题。问题是!他竟然无缘无故爆栈!! 心情都爆没了。超想骂数据。。后来看到标程时。。

这三条语句不知道干什么的:

int size = 256 << 20; // 256MB/
char *p = (char*)malloc(size) + size;
__asm__("movl %0, %%esp\n" :: "r"(p) );

百度后发现跟什么寄存器有关系。。。可是这跟我爆栈有关系么??

当我把这几句删掉后,标程都是爆栈。。  然后我就彻底无语了。。。真的无语了。。真的真的很无语。。 我实在很佩服当时那些能AC的大牛们。。真不知道你们怎么解决爆栈的问题的。。

/*
* @author ipqhjjybj
* @date 20130727
*
*/
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime> #include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b)) const int N=222222,M=2222222;
int dfn[N],low[N],sig,ret,firstEdge[N],nextEdge[M],to[M],cnt,vst[M],dp[N][2];
int n,m;
void addEdge(int u,int v){
to[cnt]=v;
nextEdge[cnt]=firstEdge[u];
firstEdge[u]=cnt++;
}
void tarjan(int u){
dp[u][0]=dp[u][1]=0;
dfn[u]=low[u]=sig++;
for(int st=firstEdge[u];st!=-1;st=nextEdge[st]){
if(!vst[st>>1]){
vst[st>>1]=1;
int v=to[st];
if(dfn[v]==-1){
tarjan(v);
low[u]=min(low[u],low[v]);
ret+=dfn[u]<low[v];
int temp=dp[v][0]+(dfn[u]<low[v]);
if(temp>dp[u][0]){
dp[u][1]=dp[u][0];
dp[u][0]=temp;
}else if(temp>dp[u][1])
dp[u][1]=temp;
}else{
low[u]=min(low[u],dfn[v]);
}
}
}
}
int main(){
//freopen("1002.in","r",stdin);
int size = 256 << 20; // 256MB/
char *p = (char*)malloc(size) + size;
__asm__("movl %0, %%esp\n" :: "r"(p) );
while(scanf("%d %d",&n,&m) && n+m){
cnt=0;memset(firstEdge,-1,sizeof(firstEdge));
for(int i=0,a,b;i<m;i++){
scanf("%d %d",&a,&b);
addEdge(a-1,b-1);
addEdge(b-1,a-1);
}
memset(dfn,-1,sizeof(dfn));
memset(vst,0,sizeof(vst));
sig=0,ret=0;
tarjan(0);
int ans=0;
for(int i=0;i<n;i++)
ans=max(ans,dp[i][0]+dp[i][1]);
printf("%d\n",ret-ans);
}
return 0;
}

本来想接着用说的思路写的,就是双连通+缩点+树最长直径来做。后来看到标程这个DP用的真的很好哇。。。省了好多代码。 其实这就是找一条直径方法比较快的浓缩了。

标准程序还是挺好的,就是爆栈的数据让我无语了。。

恩。。接着决定继续好好学习

多校联赛2 Problem2 Warm up 求桥的数目+缩点后的树的直径 当时被不知道原因的爆栈爆到无语了。。的更多相关文章

  1. Warm up---hdu4612(缩点,树的直径)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 给一个无向图, 加上一条边后,求桥最少有几个: 那我们加的那条边的两个顶点u,v:一定是u,v之 ...

  2. [HDOJ4612]Warm up(双连通分量,缩点,树直径)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 所有图论题都要往树上考虑 题意:给一张图,仅允许添加一条边,问能干掉的最多条桥有多少. 必须解决 ...

  3. xdoj-1319 求树上任意一点的最大距离----利用树的直径

    1 #include <bits/stdc++.h> using namespace std; ; vector < vector <int> > g(N); in ...

  4. (求树的直径)Warm up -- HDU -- 4612

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 给一个无向图, 加上一条边后,求桥至少有几个: 那我们加的那条边的两个顶点u,v:一定是u,v之 ...

  5. poj 3177 Redundant Paths【求最少添加多少条边可以使图变成双连通图】【缩点后求入度为1的点个数】

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11047   Accepted: 4725 ...

  6. hdu 4612 Warm up 双连通缩点+树的直径

    首先双连通缩点建立新图(顺带求原图的总的桥数,事实上因为原图是一个强连通图,所以桥就等于缩点后的边) 此时得到的图类似树结构,对于新图求一次直径,也就是最长链. 我们新建的边就一定是连接这条最长链的首 ...

  7. HDU 4612 Warm up (边双连通分量+缩点+树的直径)

    <题目链接> 题目大意:给出一个连通图,问你在这个连通图上加一条边,使该连通图的桥的数量最小,输出最少的桥的数量. 解题分析: 首先,通过Tarjan缩点,将该图缩成一颗树,树上的每个节点 ...

  8. 2015 HDU 多校联赛 5363 Key Set

    2015 HDU 多校联赛 5363 Key Set 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5363 依据前面给出的样例,得出求解公式 fn = ...

  9. 2015 HDU 多校联赛 5317 RGCDQ 筛法求解

    2015 HDU 多校联赛 5317 RGCDQ 筛法求解 题目  http://acm.hdu.edu.cn/showproblem.php? pid=5317 本题的数据量非常大,測试样例多.数据 ...

随机推荐

  1. ulimit 参数介绍

    Linux对于每个用户,系统限制其最大进程数.为提高性能,可以根据设备资源情况,设置各linux 用户的最大进程数 可以用ulimit -a 来显示当前的各种用户进程限制.下面我把某linux用户的最 ...

  2. View not attached to window manager

    java.lang.IllegalArgumentException: View not attached to window manager 在用ProgressDialog的时候,任务结束后Dis ...

  3. 错误记录--更改tomcat端口号方法,Several ports (8005, 8080, 8009)

    启动Tomcat服务器报错: Several ports (8005, 8080, 8009) required by Tomcat v5.5 Server at localhost are alre ...

  4. 将 varchar 值转换为 JDBC 数据类型 DATE 时发生错误。

    问题是: 我是这样解决的  : 网上的 转型方法 并不好使 ,我想了想 可能是由于返回值是String  我 就成功的解决错误了  ..下面是关于原理的讲解肯定方法不唯一   至于错误,的产生,这个肯 ...

  5. 系统提供的UIImagePickerController

    1.从系统相册中读取 /* 判断选择的读取类型是否支持 UIImagePickerControllerSourceTypePhotoLibrary,普通相册 UIImagePickerControll ...

  6. IOC设计模式初步了解(day02)

    IOC(Inversion of Control):控制反转. *其他解释:依赖注入.依赖反转…… 设计目标:简化JEE的研发工作,提供IOC容器,控制bean的生成.注入,解耦. 看了网上的一些帖子 ...

  7. mysql-cluster集群原理介绍和搭建步骤(四个data/sql节点) (转)

    MySQL簇概述 MySQL簇是一种技术,该技术允许在无共享的系统中部署“内存中”数据库的簇.通过无共享体系结构,系统能够使用廉价的硬件,而且对软硬件无特殊要求.此外,由于每个组件有自己的内存和磁盘, ...

  8. 三组I/O复用模型的比较

    概论: select.poll和epoll三组I/O复用系统调用,这3组系统调用都能同时监听多个文件描述符.它们将等待由timeout参数指定的超时时间,直到一个或者多个文件描述符上有事件发生时返回. ...

  9. 转载:js实现上传图片时 点击浏览后 就可以看到缩略图 很实用

    转载网址:http://blog.sina.com.cn/s/blog_6094f04d0100o6kj.html <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  10. 做好织梦dedecms安全防护全部方法

    很多同学遇到网站被攻击挂马,大都不是竞争对手所为.多数情况下是黑客利用工具批量扫描入侵的.因此安全防护自关重要. 织梦安装时注意: 修改默认数据库前缀: 在dedecms安装的时候修改下数据库的表前缀 ...