HDU 4738 双连通分量 Caocao's Bridges】的更多相关文章

求权值最小的桥,考虑几种特殊情况: 图本身不连通,那么就不用派人去了 图的边双连通分量只有一个,答案是-1 桥的最小权值是0,但是也要派一个人过去 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <stack> using namespace std; + ; + ; int…
第一个答案是统计图中桥的个数 如果一个点-双连通分量中边的个数大于点的个数那么这个块中所有的边都是冲突的,累加到第二个答案中去. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <map> #include <stack> #define MP make_pair…
思路就是求边双连通分量,然后缩点,再用树形DP搞一下. 代码和求强连通很类似,有点神奇,=_=,慢慢消化吧 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <stack> using namespace std; + ; + ; int n, m; int a[maxn]; struct Edge { int v, nxt;…
2013 ACM/ICPC Asia Regional Hangzhou Online 题目大意:有n个岛,曹操在一些岛之间建了一些桥,每个桥上有一些士兵把守,周瑜只有一个炸弹只能炸掉一个桥,炸弹需要士兵                   带过去,士兵的数量不能小于目标桥的守卫,求出最少要派出多少士兵. 比赛一开始yyf就跟我说第一题是联通题,把题意跟我说了一下,我就知道是双联通求桥,但是看到比赛一开始第一题一片血红色,就觉得肯定有坑,自己写了一遍,结果wrong了.后来才知道这题有两个坑,如…
九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711577 题意:给定n个点,m条无向边 下面m行表示u , v ,边权值 求所有桥中最小的桥的权值,如不存在输出-1 若图一开始就不连通或最小权值为0则输出1 双连通求桥裸题 附赠一大波测试数据: #include <string.h> #include <cstdio> #include <vector> #define N 1010 #defi…
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3000    Accepted Submission(s): 953 Problem Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. Bu…
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3992    Accepted Submission(s): 1250 Problem Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:给一些点,用一些边把这些点相连,每一条边上有一个权值.现在要你破坏任意一个边(要付出相应边权值的代价),使得至少有两个连通块.输出最小代价值. 算法思路:这题坑多,要考虑仔细: 1.图是边双连通图,就做不到删除一边得到两个连通块,这种情况输出-1. 2.图是连通但不边双联通,就用tarjan找出桥中权值最小的,这里有个巨坑,如果桥最小的权值为0,这时根据题意,要输出1而不是0(看看题…
 Caocao's Bridges Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4738 Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. But he wouldn't give up. Caocao's army s…
HDU 4738 Caocao's Bridges 题目链接 注意几个坑,可能重边,至少要派一个人去炸,没有连通的时候就不用炸了 代码: #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int N = 1005; const int INF = 0x3f3f3f3f; int pre[N], low[N…
题目链接: Hdu 4738 Caocao's Bridges 题目描述: 有n个岛屿,m个桥,问是否可以去掉一个花费最小的桥,使得岛屿边的不连通? 解题思路: 去掉一个边使得岛屿不连通,那么去掉的这个边一定是一个桥,所以我们只需要求出来所有的桥,然后比较每个桥的花费,选取最小的那个就好. 看起来很简单的样子哦!但是这个题目有很多的细节: A:题目中有重边,以后写Tarjan还是清一色判断重边吧.(除非题目特别要求) B:m个桥有可能连通不了这n个桥,这个时候不需要花费. C:当最小花费桥的花费…
http://acm.hdu.edu.cn/showproblem.php?pid=4738 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5067    Accepted Submission(s): 1589 Problem Description Caocao was defeated by Zhuge Liang and Zho…
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1231    Accepted Submission(s): 478 Problem Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. B…
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. But he wouldn't give up. Caocao's army still was not good…
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 194    Accepted Submission(s): 89 Problem Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. But…
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5050    Accepted Submission(s): 1584 Problem Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi.…
题目描述 Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. But he wouldn't give up. Caocao's army still was not good at water battles, so he came up with another idea. He built many islands in the Changjiang river, and based on those…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 给一张无向图,每一条边都有权值.找一条割边,使得删掉这条边双连通分量数量增加,求权值最小那条. 注意有重边,ACEveryDay里群巨给的意见是tarjan的时候记录当前点是从哪条边来的. 注意假如桥的权值是0的时候也得有一个人去炸…… 在找割边的时候,假如用点做线索,比如a到b有两条无向边. 现在是有重边的情况,假如现在从a点到b点,根据线索,我们认为a是b的父亲了,那我们从b点再回去的边就…
Warm up Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4612 Description N planets are connected by M bidirectional channels that allow instant transportation. It's always possible to travel bet…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 Problem Description Given an undirected connected graph G with n nodes and m edges, with possibly repeated edges and/or loops. The stability of connectedness between node u and node v is defined by…
Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 90    Accepted Submission(s): 12 Problem Description N planets are connected by M bidirectional channels that allow instant transportatio…
Burning Bridges Time Limit: 5 Seconds      Memory Limit: 32768 KB Ferry Kingdom is a nice little country located on N islands that are connected by M bridges. All bridges are very beautiful and are loved by everyone in the kingdom. Of course, the sys…
http://acm.hdu.edu.cn/showproblem.php?pid=2242 题意: 思路:首先求一下双连通分量,如果只有一个双连通分量,那么无论断哪根管子,图还是连通的. 最后只需要根据双连通分量重新建图,在树上进行dp,分成两部分的最小差值.这个具体看代码就可以了. 需要注意的是,这道题目是存在重边的,在这个点上我WA了好久,那么怎么处理重边呢? 设置一个重边标记,跳过第一次父亲结点的反向边,但是第二次的话就必须处理,此时就是双连通的了. 简单来说,如果图是没有重边的,那么我…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2460 思路:题目的意思是要求在原图中加边后桥的数量,首先我们可以通过Tarjan求边双连通分量,对于边(u,v),如果满足low[v]>dfn[u],则为桥,这样我们就可以知道图中桥的数目了.对于每一次query,可以考虑dfs树,树边肯定是桥,然后连上u,v这条边之后,就会形成一个环,这样环内的边就不是割边了,所以只要找到u,v的LCA,把这个路径上的桥标记为否就可以了. http://paste…
题意: 给出一个无向连通图,有\(m\)次操作,每次在\(u, v\)之间加一条边,并输出此时图中桥的个数. 分析: 先找出边双连通分量然后缩点得到一棵树,树上的每条边都输原图中的桥,因此此时桥的个数为树的节点个数减一. 然后每次添加一条边,相当于将树上对应节点\(u, v\)之间的边都变为非桥的边. 每次暴力修改每条边的标记即可,还想更快一点的话还可以用树链剖分加速. #include <cstdio> #include <cstring> #include <algori…
Problem Description City C is really a nightmare of all drivers for its traffic jams. To solve the traffic problem, the mayor plans to build a RTQS (Real Time Query System) to monitor all traffic situations. City C is made up of N crossings and M roa…
[题意]给定一个无向图,问在允许加一条边的情况下,最少的桥的个数 [思路]对图做一遍Tarjan找出桥,把双连通分量缩成一个点,这样原图就成了一棵树,树的每条边都是桥.然后在树中求最长链,这样在两端点间连一条边就能形成环从而减少桥数. 不能更逗比..多校第一场刚做出来的找最长链第二场就做错了= =,还一直以为是模板的问题...... #include #include #include #include #include #include #define MID(x,y) ((x+y)/2) #…
题意: 给一个图n个点m条边(不一定连通),接下来又q个询问,询问两个点是为“不相连”,“仅有一条路径可达”,“有两条及以上的不同路径可达”三种情况中的哪一种.注:两条以上的路径指的是路径上的点连1个点也不重复. 思路:并查集+tarjan求割点. (1)情况一:先并查集处理,如果两个点从一开始就不连通,直接输出zero (2)情况二和情况三:两点既然连通,那么可能是只有1条路径,比如中间隔着一个割点:也可能有多条路径,比如在同一个双连通分量内.那么直接判断其是否在同一个双连通分量内即可,若在同…
Cycle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 865    Accepted Submission(s): 241 Problem Description Ery is interested in graph theory, today he ask BrotherK a problem about it: Given…
<题目链接> 题目大意:给出一个连通图,问你在这个连通图上加一条边,使该连通图的桥的数量最小,输出最少的桥的数量. 解题分析: 首先,通过Tarjan缩点,将该图缩成一颗树,树上的每个节点都是一个边双连通分量,树上的每条边都是桥,现在需要挑出两个点,将它们直接相连,这样它们原始路径上所有的桥因为形成了环而全部消失,因此为了使剩下的桥最少,我们需要找到路径上桥最多的两点,又由于缩点后,树的每条边都是桥,所以这里就转化为树上距离两点的最远距离,也就是求树的直径. 下面Tarjan的时候需要注意的是…