博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉
阅读量:6476 次
发布时间:2019-06-23

本文共 2560 字,大约阅读时间需要 8 分钟。

Problem D. Distance

题目连接:

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
using namespace std;const int maxn = 1e5+6;const int inf = 1e9+1e7;vector
> E[maxn];int n,k,l;int vis[maxn],use[maxn],dis[maxn],color[maxn];vector
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
>S; for(int i=0;i
second; S.erase(S.begin()); for(int i=0;i
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<
<

转载地址:http://ibmko.baihongyu.com/

你可能感兴趣的文章
【Android 基础】Android中全屏或者取消标题栏
查看>>
Xilinx 常用模块汇总(verilog)【03】
查看>>
脱离标准文档流(2)---定位
查看>>
IO流之字符流
查看>>
集合异常之List接口
查看>>
Softmax回归
查看>>
紫书 习题11-11 UVa 1644 (并查集)
查看>>
App工程结构搭建:几种常见Android代码架构分析
查看>>
使用openssl进行证书格式转换
查看>>
ZOJ 3777 Problem Arrangement
查看>>
虚拟机类加载机制
查看>>
Callable和Future
查看>>
installshield12如何改变默认安装目录
查看>>
少用数字来作为参数标识含义
查看>>
ScrollView中嵌套ListView
查看>>
JAVA虚拟机05--面试必问之JVM原理
查看>>
Algs4-2.3.1如何切分数组
查看>>
uva 10815 - Andy's First Dictionary(快排、字符串)
查看>>
观察者模式
查看>>
在properties.xml中定义变量,在application.xml中取值问题
查看>>