2015 ACM/ICPC Asia Regional Changchun Online Pro 1005 Travel (Krsukal变形)
Travel
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 46 Accepted Submission(s): 20
bidirectional roads connecting the cities. Jack hates waiting too long
on the bus, but he can rest at every city. Jack can only stand staying
on the bus for a limited time and will go berserk after that. Assuming
you know the time it takes to go from one city to another and that the
time Jack can stand staying on a bus is x minutes, how many pairs of city (a,b) are there that Jack can travel from city a to b without going berserk?
For each test case, the first line consists of three integers n,m and q where n≤20000,m≤100000,q≤5000. The Undirected Kingdom has n cities and m bidirectional roads, and there are q queries.
Each of the following m lines consists of three integers a,b and d where a,b∈{1,...,n} and d≤100000. It takes Jack d minutes to travel from city a to city b and vice versa.
Then q lines follow. Each of them is a query consisting of an integer x where x is the time limit before Jack goes berserk.
Note that (a,b) and (b,a) are counted as different pairs and a and b must be different cities.
#include<bits/stdc++.h>
using namespace std;
const int maxq = 5e3+;
int Qry[maxq];
long long ans[maxq];
bool cmp(int a,int b) { return Qry[a] < Qry[b]; }
int rk[maxq];
int n,m,q; const int maxm = 1e5+,maxn = 2e4+;
struct Edge
{
int u,v,w;
bool operator < (const Edge &rh) const {
return w < rh.w;
}
void IN() {
scanf("%d%d%d",&u,&v,&w);
}
}edges[maxm]; int pa[maxn],cnt[maxn];
int fdst(int x) { return x==pa[x]?x:pa[x]=fdst(pa[x]); } int main()
{
//freopen("in.txt","r",stdin);
int T; scanf("%d",&T);
while(T--){
scanf("%d%d%d",&n,&m,&q);
for(int i = ; i < m ;i++){
edges[i].IN();
}
for(int i = ; i < q; i++){
rk[i] = i; scanf("%I64d",Qry+i);
}
sort(rk,rk+q,cmp);
sort(edges,edges+m);
for(int i = ; i <= n; i++) pa[i] = i,cnt[i] = ;
long long cur = ;
for(int i = ,j = ; i < q; i++){
int id = rk[i];
int cq = Qry[id];
while(j < m && edges[j].w <= cq){
int u = fdst(edges[j].u),v = fdst(edges[j].v);
if(u != v){
pa[u] = v;
cur += 2LL*cnt[u]*cnt[v];
cnt[v] += cnt[u];
}
j++;
}
ans[id] = cur;
}
for(int i = ; i < q; i++){
printf("%I64d\n",ans[i]);
}
}
return ;
}
2015 ACM/ICPC Asia Regional Changchun Online Pro 1005 Travel (Krsukal变形)的更多相关文章
- 2015 ACM/ICPC Asia Regional Changchun Online Pro 1008 Elven Postman (BIT,dfs)
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2015 ACM/ICPC Asia Regional Changchun Online Pro 1002 Ponds(拓扑排序+并查集)
Ponds Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Sub ...
- hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...
- (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )
http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others) Memo ...
- (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)
http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others) ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- (线段树 区间查询)The Water Problem -- hdu -- 5443 (2015 ACM/ICPC Asia Regional Changchun Online)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java/ ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU - 5441 (离线+并查集)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5441 题意:给你n,m,k,代表n个城市,m条边,k次查询,每次查询输入一个x,然后让你一个城市对(u,v ...
- hdu 5444 Elven Postman(根据先序遍历和中序遍历求后序遍历)2015 ACM/ICPC Asia Regional Changchun Online
很坑的一道题,读了半天才读懂题,手忙脚乱的写完(套上模板+修改模板),然后RE到死…… 题意: 题面上告诉了我们这是一棵二叉树,然后告诉了我们它的先序遍历,然后,没了……没了! 反复读题,终于在偶然间 ...
随机推荐
- 21.运行Consent Page
服务端把这个地方修改为true,需要设置 运行测试.服务端和客户端都运行起来 我们使用的用户是在这里配置的 服务端修改ConsentController 再次运行,但是页面都是乱码 openId和pr ...
- 猜socklen_t的原型
编写tcp时碰到这个类型,感觉他就是int型. 百度了一下: typedef int socklen_t typedef int ssize_t 我去/usr/include 下grep -r soc ...
- HDU5381【莫队算法+区间GCD特性】
前言: 主要最近在刷莫队的题,这题GCD的特性让我对莫队的使用也有了新的想法.给福利:神犇的一套莫队算法题 先撇开题目,光说裸的一个莫队算法,主要的复杂度就是n*sqrt(n)对吧,这里我忽略了一个左 ...
- Unity 5.6中的混合光照(上)
https://mp.weixin.qq.com/s/AbWM21sihHw5pFdMzENDPg 在Unity 5中,光照得到了很大的改进.现在,创建高度逼真的游戏已成为可能.但是,出于对性能的考虑 ...
- IT兄弟连 Java语法教程 Java平台的版本划分
自从Sun公司推出Java以来,就力图使之无所不能.Java发展至今,按应用范围划分为3个版本,即Java SE.Java EE和Java ME,也就是SunOne(Open Net Environm ...
- left join on 和where条件的放置(转)
http://blog.csdn.net/muxiaoshan/article/details/7617533
- CC06:像素翻转
题目 有一副由NxN矩阵表示的图像,这里每个像素用一个int表示,请编写一个算法,在不占用额外内存空间的情况下(即不使用缓存矩阵),将图像顺时针旋转90度. 给定一个NxN的矩阵,和矩阵的阶数N,请返 ...
- safari不支持new Date函数
最近在做移动Web的时候,在PC上用Chrome调试都成功了,但是在iPhone上真机一测就出现了奇怪的问题.经过一系列调试发现是日期相关的地方出现了问题.起初怀疑是生产环境的问题,但用Mac版的sa ...
- Java NIO 必知必会(Example)
管道流: Java NIO 管道是2个线程之间的单向数据连接.Pipe有一个source通道和一个sink通道.数据会被写到sink通道,从source通道读取. package base.nio.t ...
- virtualenv模块安装
依赖包管理模块(virtualenv) virtualenv是Python的虚拟环境,可以在同一台PC隔离不同的python开发环境.virtualenv可以创建一个隔离的python环境(沙盒).使 ...