HDU 3938
来源:互联网 发布:外汇牌价走势图软件 编辑:程序博客网 时间:2024/06/06 07:41
Portal
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1796 Accepted Submission(s): 884
Problem Description
ZLGG found a magic theory that the bigger banana the bigger banana peel .This important theory can help him make a portal in our universal. Unfortunately, making a pair of portals will cost min{T} energies. T in a path between point V and point U is the length of the longest edge in the path. There may be lots of paths between two points. Now ZLGG owned L energies and he want to know how many kind of path he could make.
Input
There are multiple test cases. The first line of input contains three integer N, M and Q (1 < N ≤ 10,000, 0 < M ≤ 50,000, 0 < Q ≤ 10,000). N is the number of points, M is the number of edges and Q is the number of queries. Each of the next M lines contains three integers a, b, and c (1 ≤ a, b ≤ N, 0 ≤ c ≤ 10^8) describing an edge connecting the point a and b with cost c. Each of the following Q lines contain a single integer L (0 ≤ L ≤ 10^8).
Output
Output the answer to each query on a separate line.
Sample Input
10 10 107 2 16 8 34 5 85 8 22 8 96 4 52 1 58 10 57 3 77 8 810615918276
Sample Output
36131133613621613
Source
2011 Multi-University Training Contest 10 - Host by HRBEU
Recommend
We have carefully selected several similar problems for you: 3935 3937 3931 3932 3933
题意:从u到v两点之间建立路径花费精力是其中路段cost最多的那个,Q次询问给你总精力为L,求出有多少种类的路径被建成
将询问按照从小到大排序,然后将每条边按照权值从小到大排序,对于当前加入树边(u,v,w),对应ans【w】=sum【u】*sum【v】,这里sum【u】表示的就是点u所在联通块点的个数。
#include <algorithm>#include <iostream>#include <cstring>#include <cstdio>#include <queue>using namespace std;#define N 110000struct node { int u,v; int w;}edge[N*5];struct Node { int pos; int val;}a[N];int father[N];int num[N], ans[N];int n, m, q;bool cmp1(node a, node b){ return a.w < b.w;}bool cmp2(Node a, Node b){ return a.val < b.val;}int findfather(int x){ int a = x; while(x != father[x]) x = father[x]; while(a != father[a]) { int t = a; a = father[a]; father[t] = x; } return x;}int Union(int a, int b){ int faA = findfather(a); int faB = findfather(b); if(faA == faB) //如果合并后属于同一子集说明已经被联通两点已经被计算在内 return 0; int t = num[faA] * num[faB]; father[faB] = faA; num[faA] += num[faB]; num[faB] = 0;//已经合并在一个集合里防止重复 return t;}int main(){ while(scanf("%d%d%d", &n, &m, &q) != EOF) { for(int i = 0; i <= n; i++) { father[i] = i; num[i] = 1; } for(int i = 0; i < m; i++) scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].w); sort(edge, edge + m, cmp1); //边长从小到大排序 for(int i = 0; i < q; i++) { scanf("%d", &a[i].val); a[i].pos = i; } sort(a, a+q, cmp2); int t = 0; int j = 0; for(int i = 0; i < q; i++) { while(j < m && edge[j].w <= a[i].val) { t += Union(edge[j].u, edge[j].v); j++; } ans[a[i].pos] = t; } for(int i = 0; i < q; i++) printf("%d\n", ans[i]); } return 0;}
阅读全文
0 0
- hdu 3938
- HDU 3938
- HDU 3938
- hdu 3938 Portal
- hdu 3938 Portal
- hdu 3938 Portal
- HDU 3938 Portal
- hdu 3938 Portal
- hdu 3938 Portal
- hdu 3938 Portal
- HDU 3938 Portal
- HDU-3938-Portal
- HDU 3938 Portal
- hdu
- hdu
- HDU
- hdu ()
- hdu
- 输入输出管理及文件权限的练习
- 蓝桥杯算法训练 P1103(复数运算)
- 从DialogFragment回传数据给CrimeFragment
- 16进制转8进制
- android Apk打包过程概述_android是如何打包apk的
- HDU 3938
- 爬格子呀5-5
- 并归排序算法
- JSTL – I18N - 国际化标签库。
- impdp导入数据无权限ORA-39213错误
- 图文讲解Zabbix 分布式监控平台添加服务监控项
- centos6.5上安装mysql
- SEO单页优化技巧与软文推广
- 【数据结构】1.概论