Caocao's Bridges-HDU4738(Tarjin+求桥)】的更多相关文章

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.…
题目描述 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 题目大意: 给定n个点和m条边  和每条边的价值,求桥的最小价值(最小桥) 看着挺简单的但是有好多细节: 1.会有重边 2.如果最小价值是0的话应该输出1 3.m条边有可能不能连通n个点,这个时候没有花费. Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others…
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4254    Accepted Submission(s): 1337 Problem Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. B…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题意:有n座岛和m条桥,每条桥上有w个兵守着,现在要派不少于守桥的士兵数的人去炸桥,只能炸一条桥,使得这n座岛不连通,求最少要派多少人去. 分析:只需要用Tarjan算法求出图中权值最小的那条桥就行了.但是这题有神坑. 第一坑:如果图不连通,不用派人去炸桥,直接输出0 第二坑:可能会有重边 第三坑:如果桥上没有士兵守着,那至少要派一个人去炸桥. 比赛的时候看完就想做了,但是图论太挫了,居然不会…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题意:给定一个n个节点m条边的无向图(可能不连通.有重边),每条边有一个权值.判断其连通性,若双连通,输出-1:若非连通,输出0:否则,输出权值最小的桥的权值. 思路:进行双连通域分解,记下连通块的个数和所有桥的情况,对应输出结果即可. 注意对重边的处理.这里我按照上一道题学到的姿势如法炮制:先把所有边按“字典序”排序(u, v, w),这样重边聚集在一起了,然后扫描一遍,发现重边即在结构体E…
题意: 曹操在赤壁之战中被诸葛亮和周瑜打败.但他不会放弃.曹操的军队还是不擅长打水仗,所以他想出了另一个主意.他在长江上建造了许多岛屿,在这些岛屿的基础上,曹操的军队可以轻易地攻击周瑜的军队.曹操还修建了连接岛屿的桥梁.如果所有的岛屿都用桥连接起来,曹操的军队就可以很方便地部署在这些岛屿之间.周瑜无法忍受,他想毁掉曹操的一些桥梁,把一个或多个岛屿与其他岛屿分开.周瑜身上只有一颗炸弹,是诸葛亮留下的,所以他只能毁掉一座桥.周瑜必须派人带着炸弹去炸毁那座桥.桥上可能有警卫.轰炸队的士兵人数不能少于一…
神坑题.这题的坑点有1.判断连通,2.有重边,3.至少要有一个人背*** 因为有重边,tarjan的时候不能用子结点和父节点来判断是不是树边的二次访问,所以我的采用用前向星存边编号的奇偶性关系,用^1来判断是不是树边 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxe = 1000005<<1; const int maxv =…
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8476    Accepted Submission(s): 2604 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 Description: Caocao was defeated by Zhug…
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: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…
Caocao's Bridges 题意:曹操赤壁之战后卷土重来,他在n个小岛之间建立了m座桥.现在周瑜只有一颗炮弹,他只能炸毁一座桥使得这些岛屿不再连通.每座桥上都可能会有士兵把手,如果想安放***那么派出的士兵就不得少于桥上的士兵.求周瑜最少需要多少士兵. 思路:首先三大坑点:图原来就不连通所以不用炸毁任何一座桥.两个小岛之间有重边,那么不管炸毁哪座都无影响,也就是说重边不是桥.如果桥上本来就没有士兵是不是不用派出呢, 当然不是,还要一个放***的啊..... int ti,top,ans,q…
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10933    Accepted Submission(s): 3065 Problem Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi.…
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…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:给一些点,用一些边把这些点相连,每一条边上有一个权值.现在要你破坏任意一个边(要付出相应边权值的代价),使得至少有两个连通块.输出最小代价值. 算法思路:这题坑多,要考虑仔细: 1.图是边双连通图,就做不到删除一边得到两个连通块,这种情况输出-1. 2.图是连通但不边双联通,就用tarjan找出桥中权值最小的,这里有个巨坑,如果桥最小的权值为0,这时根据题意,要输出1而不是0(看看题…
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…
题目链接: Hdu 4738 Caocao's Bridges 题目描述: 有n个岛屿,m个桥,问是否可以去掉一个花费最小的桥,使得岛屿边的不连通? 解题思路: 去掉一个边使得岛屿不连通,那么去掉的这个边一定是一个桥,所以我们只需要求出来所有的桥,然后比较每个桥的花费,选取最小的那个就好. 看起来很简单的样子哦!但是这个题目有很多的细节: A:题目中有重边,以后写Tarjan还是清一色判断重边吧.(除非题目特别要求) B:m个桥有可能连通不了这n个桥,这个时候不需要花费. C:当最小花费桥的花费…
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.…
Network Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3694 Description A network administrator manages a large network. The network consists of N computers and M links between pairs of compute…
这个题使我更深理解了TARJAN算法,题意:无向图,每添加一条边后文桥的数量,三种解法:(按时间顺序),1,暴力,每每求桥,听说这样能过,我没过,用的hash判重,这次有俩个参数(n->10w,开不了二维的),怎么判?联系2个参数,我想到了用一个函数,像散列一样,定义关系,我随便写了一个hash[x+y+x/y+y/x+x%y+y%x+x|y],一直WA,虽然未过,但是想到了这个,以后2个参数判重可以用之!2.网上学习了算法,将之缩点成树,每个双连通分量用一个点表示,用一个数组tree[i],点…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737 桥: 一个连通图,无向连通图中,如果删除某条边后,图变成不连通了,则该边为桥: 求桥: 在求割点的基础上吗,假如一个边没有重边(重边 1-2, 1->2 有两次,那么 1->2 就是有两条边了,那么 1->2就不算是桥了). 当且仅当 (u,v) 为父子边,且满足 d…
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…
题目链接:https://vjudge.net/problem/HDU-4738 题目:tarjan求桥,坑点: 题目说是分岛任务...如果所有岛之间没有完全连通,就不需要执行任务了...答案直接是0... 桥上可能没人,但是,炸弹需要一个人去送,所以至少1个人. #include <iostream> #include <cstdio> #include <algorithm> using namespace std; ; int n,m,tot,tim,solder…
若low[v]>dfn[u],则(u,v)为割边.但是实际处理时我们并不这样判断,因为有的图上可能有重边,这样不好处理.我们记录每条边的标号(一条无向边拆成的两条有向边标号相同),记录每个点的父亲到它的边的标号,如果边(u,v)是v的父亲边,就不能用dfn[u]更新low[v].这样如果遍历完v的所有子节点后,发现low[v]=dfn[v],说明u的父亲边(u,v)为割边. void tarjan(int x) { vis[x]=1; dfn[x]=low[x]=++num; for(int i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 题目大意:给你一个无向图,问你加一条边后最少还剩下多少多少割边. 解题思路:好水的一道模板题.先缩点变成一颗树,再求树的最长直径,直径两端连一条边就是最优解了. 但是....我WA了一个下午.....没有处理重边. 重边的正确处理方法:只标记已经走过的正反边,而不限制已走过的点.换句话说就是可以经过重边再次走向父亲节点,而不能经过走过边的反向边返回父亲节点. #pragma comment(l…
POJ 3177 Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12598   Accepted: 5330 Description In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the re…
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…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737 题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号  (与这个点相连的点的个数m)  依次是m个点的   输入到文件结束. 桥输出的时候需要排序   知识汇总: 桥:   无向连通图中,如果删除某条边后,图变成不连通了,则该边为桥. 求桥: 在求割点的基础上,假如一…
一道简单的双联通求桥的题目,,数据时字符串,,map用的不熟练啊,,,,,,,,,,,,, #include <iostream> #include <cstring> #include <cstdio> #include <map> #include <string> #include <algorithm> #define N 10001 using namespace std; int head[N],num,dfs[N],lo…
题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号  (与这个点相连的点的个数m)  依次是m个点的   输入到文件结束. 桥输出的时候需要排序   知识汇总: 桥:   无向连通图中,如果删除某条边后,图变成不连通了,则该边为桥. 求桥: 在求割点的基础上吗,假如一个边没有重边(重边 1-2, 1->2 有两次,那么 1->2 就是有两条边了,那么 1->2就不算是桥了). 当且仅当 (u,v) 为父子边,且满足 dfn[u] < low[v] 这里对重边处理…