2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉
Problem D. Distance
题目连接:
http://codeforces.com/gym/100714
Description
In a large city a cellular network operator is holding a competition for subscribers to promote their new
“pedestrian navigator” service. The main prize will be awarded to the first pair of subscribers to meet
each other. The competition ends when any such meeting takes place.
At the start of the competition all the subscribers are at their known positions, are able to see each other
on their smartphones, and are moving at a constant speed of 10 km/h taking only pedestrian walks. Each
subscriber is willing to win the prize and is indifferent to the others.
In order to prepare for an award ceremony the cellular network operator needs to know the minimal
amount of time after which the competition may come to an end.
Input
In the first line of input integers N, K, and L are given — the number of subscribers in a cellular network
company (2 ≤ N ≤ 105
), the number of junctions (1 ≤ K ≤ 105
), and the number of pedestrian walks
(1 ≤ L ≤ 105
) in the city, respectively.
On the next N lines of input Si (1 ≤ Si ≤ K) numbers are given — initial positions of subscribers (in
the terms of transport graph junctions).
The next L lines of input pedestrian paths are given in the form of integers Bi
, Ci and Di separated
by spaces. Each line denotes that there is a two-way pedestrian path between junctions Bi and Ci
(1 ≤ Bi
, Ci ≤ K, Bi 6= Ci) with a length of Di (1 ≤ Di ≤ 5000) kilometers.
Output
Output the minimal possible number of minutes that may elapse from the start till the end of the contest.
It is guaranteed that at least one pair of the subscribers can meet.
Sample Input
2 2 1
1
2
1 2 5
Sample Output
15
Hint
题意
有n个关键点,这个图一共有m个点,l条边,问你两个关键点之间最短距离是多少
题解:
暴力dij就好了,记录一下这个点的最短路是谁。
然后边松弛边统计答案就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+6;
const int inf = 1e9+1e7;
vector<pair<int,int> > E[maxn];
int n,k,l;
int vis[maxn],use[maxn],dis[maxn],color[maxn];
vector<int> st;
int main(){
scanf("%d%d%d",&n,&k,&l);
for(int i=1;i<=n;i++){
int x;scanf("%d",&x);
st.push_back(x);
}
for(int i=1;i<=l;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
E[a].push_back(make_pair(b,c));
E[b].push_back(make_pair(a,c));
}
int ans = inf;
for(int i=1;i<=k;i++){
dis[i]=inf;
vis[i]=-1;
}
set<pair<int,int> >S;
for(int i=0;i<st.size();i++){
dis[st[i]]=0;
color[st[i]]=i;
S.insert(make_pair(0,st[i]));
if(use[st[i]]){
ans=0;
}
use[st[i]]=1;
}
while(!S.empty()){
int now = S.begin()->second;
S.erase(S.begin());
for(int i=0;i<E[now].size();i++){
int x = E[now][i].first;
int v = E[now][i].second;
if(color[x]!=color[now]&&color[x]!=-1)
ans=min(ans,v+dis[x]+dis[now]);
if(dis[x]>dis[now]+v){
S.erase(make_pair(dis[x],x));
dis[x]=dis[now]+v;
color[x]=color[now];
S.insert(make_pair(dis[x],x));
}
}
}
cout<<ans*3<<endl;
}
2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉的更多相关文章
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem C. Contest 水题
Problem C. Contest 题目连接: http://codeforces.com/gym/100714 Description The second round of the annual ...
- 2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator
题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229511 时间限制:1s 空间限制:512MB 题目大意: 给定一个n 随后跟着2n行输入 ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力
Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem J. Joke 水题
Problem J. Joke 题目连接: http://codeforces.com/gym/100714 Description The problem is to cut the largest ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem I. Interest Targeting 模拟题
Problem I. Interest Targeting 题目连接: http://codeforces.com/gym/100714 Description A unique display ad ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem H. Hometask 水题
Problem H. Hometask 题目连接: http://codeforces.com/gym/100714 Description Kolya is still trying to pass ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem F. Finance 模拟题
Problem F. Finance 题目连接: http://codeforces.com/gym/100714 Description The Big Boss Company (BBC) pri ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem A. Alien Visit 计算几何
Problem A. Alien Visit 题目连接: http://codeforces.com/gym/100714 Description Witness: "First, I sa ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
随机推荐
- [转载]jdk环境变量配置方法
JDK下载 在安装完jdk后,还需要对jdk的环境变量进行配置才能正常使用,下面教大家如何配置jdk环境变量: 1.右键选择 计算机→属性→高级系统设置→高级→环境变量 2.系统变量→新建 变量名:J ...
- 【BZOJ】2111: [ZJOI2010]Perm 排列计数 计数DP+排列组合+lucas
[题目]BZOJ 2111 [题意]求有多少1~n的排列,满足\(A_i>A_{\frac{i}{2}}\),输出对p取模的结果.\(n \leq 10^6,p \leq 10^9\),p是素数 ...
- 20155202 2016-2017-2 《Java程序设计》第5周学习总结
20155202 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 第八章:异常处理 java中所有错误会包装成对象,可以尝试(try)执行程序并捕捉(catc ...
- 【转】教你何时开启水果机上的HDR拍照
原址:http://news.mydrivers.com/1/175/175922.htm 苹果在iOS 4.1操作系统中为iPhone 4增加了一项有趣的新功能:HDR拍照.虽然目前市场上支持HDR ...
- python中的 __repr__和__str__
__repr__,被内置函数repr用于把一个对象用"官方"的字符串形式表示出来(终端友好) 1.值传给eval()来返回一个对象的字符串表示形式 2.否则返回一个尖括 ...
- js 判断日期大小、是否在时间范围内等处理
var beginval="2015-09-01";//这个时间可以是日期控件选择的,也可以是其他的任何日期时间 var endval="2015-09-01" ...
- 数链剖分(Aragorn's Story )
题目链接:https://vjudge.net/contest/279350#problem/A 题目大意:n个点,m条边,然后q次询问,因为在树上,两个点能确定一条直线,我们可以对这条直线上的所有值 ...
- Js表单验证控件
演示地址:http://weishakeji.net/Utility/Verify/Index.htm 开源地址:https://github.com/weishakeji/Verify_Js ...
- TensorFlow 从零到helloWorld
目录 1.git安装与使用 1.1 git安装 1.2 修改git bash默认路径 1.3 git常用操作 2.环境搭建 2.1 tensorflow安装 2.2 CUDA安装 2.3 ...
- python模块分析之time和datetime模块
前言 我们使用time和datetime模块的主要目的是对时间戳.时间字符串.时间元组等时间的表述对象进行相互的转化.而我们平时编码涉及两个时间:一个是上海时间,也可以说是北京时间,一个是UTC时间, ...