hdu-4612(无向图缩点+树的直径)】的更多相关文章

题目链接:https://vjudge.net/contest/67418#problem/F 题目大意:给你一个图,让你加一条边,使得原图中的桥尽可能的小.(谢谢梁学长的帮忙) 我对重边,tarjan算法中的各个数组的作用,以及需要哪些数组,还有一些不可取的地方. 重边:原来一直以为无向图没有重边,,,在进行无向图的缩点的时候,假设 u- >已经走过了,那么 在不加重边的情况下,v- > u是不能走的.如果加重边了,u->v,这个时候,假设本来v-> u 是桥,但是加了之后就不是…
题意:给你n个点和m条边的无向图,问你如果多加一条边的话,那么这个图最少的桥是什么 解题思路:无向图缩点和树的直径,用并查集缩点: #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<cstring> #include<queue> using namespace std; ; ; struct Edge { int ne…
题目链接: Hdu 4612 Warm up 题目描述: 给一个无向连通图,问加上一条边后,桥的数目最少会有几个? 解题思路: 题目描述很清楚,题目也很裸,就是一眼看穿怎么做的,先求出来双连通分量,然后缩点重新建图,用bfs求树的直径,直径的长度就是减去桥的数目. 这个题目需要手动扩展,而且手动扩展的话要用C++提交,G++re哭了. #include <cstdio> #include <queue> #include <cstring> #include <i…
Warm up 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4612 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 i…
思路:将以桥为分界的所有连通分支进行缩点,得到一颗树,求出树的直径.再用树上的点减去直径,再减一 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<queue>…
Your friend is developing a computer game. He has already decided how the game world should look like — it should consist of nn locations connected by mm two-way passages. The passages are designed in such a way that it should be possible to get from…
题目链接 Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 5353    Accepted Submission(s): 1195 Problem Description N planets are connected by M bidirectional channels that allow instant tran…
<题目链接> 题目大意:给出一个连通图,问你在这个连通图上加一条边,使该连通图的桥的数量最小,输出最少的桥的数量. 解题分析: 首先,通过Tarjan缩点,将该图缩成一颗树,树上的每个节点都是一个边双连通分量,树上的每条边都是桥,现在需要挑出两个点,将它们直接相连,这样它们原始路径上所有的桥因为形成了环而全部消失,因此为了使剩下的桥最少,我们需要找到路径上桥最多的两点,又由于缩点后,树的每条边都是桥,所以这里就转化为树上距离两点的最远距离,也就是求树的直径. 下面Tarjan的时候需要注意的是…
Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 9073    Accepted Submission(s): 2120 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 Description: N planets are connected by M bidire…
题意:一个连通无向图,问你增加一条边后,让原图桥边最少 分析:先边双缩点,因为连通,所以消环变树,每一个树边都是桥,现在让你增加一条边,让桥变少(即形成环) 所以我们选择一条树上最长的路径,连接两端,这样减少的桥边,最多,所以就是求树的直径 注:这题有重边,所以边双缩点也需要用重边版的 #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include…