HDOJ 4750 Count The Pairs
按边长从小到大排序。。。
再逐个加入(就像MST一样)最先联通的点之间最长路径中的最小值就是新加入的边的长。。。。
Count The Pairs
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 266 Accepted Submission(s): 140

With the 60th anniversary celebration of Nanjing University of Science and Technology coming soon, the university sets n tourist spots to welcome guests. Of course, Redwood forests in our university and its Orychophragmus violaceus must be recommended as top ten tourist spots, probably the best of all. Some undirected roads are made to connect pairs of tourist spots. For example, from Redwood forests (suppose it’s a) to fountain plaza (suppose it’s b), there may exist an undirected road with its length c. By the way, there is m roads totally here. Accidently, these roads’ length is an integer, and all of them are different. Some of these spots can reach directly or indirectly to some other spots. For guests, they are travelling from tourist spot s to tourist spot t, they can achieve some value f. According to the statistics calculated and recorded by us in last years, We found a strange way to calculate the value f:
From s to t, there may exist lots of different paths, guests will try every one of them. One particular path is consisted of some undirected roads. When they are travelling in this path, they will try to remember the value of longest road in this path. In the end, guests will remember too many longest roads’ value, so he cannot catch them all. But, one thing which guests will keep it in mind is that the minimal number of all these longest values. And value f is exactly the same with the minimal number.
Tom200 will recommend pairs (s, t) (start spot, end spot points pair) to guests. P guests will come to visit our university, and every one of them has a requirement for value f, satisfying f>=t. Tom200 needs your help. For each requirement, how many pairs (s, t) you can offer?
First line:n m
n tourist spots ( 1<n<=10000), spots’ index starts from 0.
m undirected roads ( 1<m<=500000).
Next m lines, 3 integers, a b c
From tourist spot a to tourist spot b, its length is c. 0<a, b<n, c(0<c<1000000000), all c are different.
Next one line, 1 integer, p (0<p<=100000)
It means p guests coming.
Next p line, each line one integer, t(0<=t)
The value t you need to consider to satisfy f>=t.
Notice, (1,2), (2,1) are different pairs.
0 1 2
3
1
2
3
3 3
0 1 2
0 2 4
1 2 5
5
0
2
3
4
5
2
0
6
6
4
4
0
#include <iostream>
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct Edge bool cmp(Edge a,Edge b) int father[550000],ran[550000]; void Init() int Find(int x) int Union(int a,int b) int main() |
* This source code was highlighted by YcdoiT. ( style: Codeblocks )
HDOJ 4750 Count The Pairs的更多相关文章
- HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)
Count The Pairs Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- [2013 ACM/ICPC Asia Regional Nanjing Online C][hdu 4750]Count The Pairs(kruskal + 二分)
http://acm.hdu.edu.cn/showproblem.php?pid=4750 题意: 定义f(u,v)为u到v每条路径上的最大边的最小值..现在有一些询问..问f(u,v)>=t ...
- hdu 4750 Count The Pairs(并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4750 代码: #include<cstdio> #include<cstring&g ...
- hdu 4750 Count The Pairs(并查集+二分)
Problem Description With the 60th anniversary celebration of Nanjing University of Science and Techn ...
- 2013南京网赛1003 hdu 4750 Count The Pairs
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4750 题意:给出一个无向图,f(a,b)表示从点a到点b的所有路径中的每条路径的最长边中的最小值,给出 ...
- HDU 4750 Count The Pairs(并查集)
题目链接 没有发现那个点,无奈. #include <cstdio> #include <cstring> #include <cmath> #include &l ...
- hdu 4750 Count The Pairs (2013南京网络赛)
n个点m条无向边的图,对于q个询问,每次查询点对间最小瓶颈路 >=f 的点对有多少. 最小瓶颈路显然在kruskal求得的MST上.而输入保证所有边权唯一,也就是说f[i][j]肯定唯一了. 拿 ...
- HDU 4750 Count The Pairs ★(图+并查集+树状数组)
题意 给定一个无向图(N<=10000, E<=500000),定义f[s,t]表示从s到t经过的每条路径中最长的边的最小值.Q个询问,每个询问一个t,问有多少对(s, t)使得f[s, ...
- HDU 4750 Count The Pairs (离线并查集)
按边从小到大排序. 对于每条边(from, to, dist),如果from和to在同一个集合中,那么这条边无意义,因为之前肯定有比它更小的边连接了from和to. 如果from和to不属于同一个集合 ...
随机推荐
- @EmbeddedId和@idClass的区别
@idClass 使复合主键类成为非嵌入类,使用 @IdClass 批注为实体指定一个复合主键类(通常由两个或更多基元类型或 JDK 对象类型组成).从原有数据库映射时(此时数据库键由多列组成),通常 ...
- [Android]Volley源码分析(三)
上篇看了关于Request的源码,这篇接着来看下RequestQueue的源码. RequestQueue类图:
- django数据库时间存储格式问题
http://blog.csdn.net/ichuzhen/article/details/38555645 一般建议用datefield 关于从数据库读取出来格式问题可以看 http://stack ...
- vc++ 中 IntelliSense: 无法打开 源 文件 "xxx.h"
类似无法找到文件的问题都可以用这个方法解决,就是路径的问题.vc++2008的项目转到vc++2010也可能出现类似的问题. 解决方法: 在 项目属性=>配置属性=>C/C++ =&g ...
- 屠蛟之路_你的名字_FirstDay
君の名は. "号外,号外!屠龙天团众志成城,惊天技杀alpha龙!号外,号外--" 苦战十日,屠龙少年们依仗最后的惊天技终于将邪恶的alpha怪龙斩杀.但是对屠龙少年而言,这是一场 ...
- vmware tools 在linux中的作用
VMware Tools是VMware虚拟机中自带的一种增强工具,相当于VirtualBox中的增强功能 是VMware提供的增强虚拟显卡和硬盘性能 以及同步虚拟机与主机时钟的驱动程序. 只有在VMw ...
- UML活动图与流程图的区别
http://blog.chinaunix.net/uid-11572501-id-3847592.html UML活动图与流程图的区别 (1).流程图着重描述处理过程,它的主要控制结构是顺序.分支和 ...
- linux 查看内存的插槽数
[root@web ~]# dmidecode|grep -P -A5 "Memory\s+Device"| grep Size | grep -v Range #linux查看内 ...
- pyqt2_官网教程
https://pythonspot.com/en/pyqt4/ Articles You can find a collection of PyQT articles below. Applicat ...
- VclZip压缩文件夹
压缩指定路径MyZipDir下的文件夹b及b目录下的所有文件和文件b.txt function ZipDir(zipMode:Integer;zipControl:TVCLZip;MyZipName, ...