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 ...
随机推荐
- THINKPHP中使用swoole
首先,运行swoole服务端程序要在命令行模式下运行php文件,所以thinkphp要设置成命令行模式运行,在入口文件中增加一个配置即可: define(‘MODE_NAME’,‘cli’); 然后运 ...
- 阿里云Linux服务器安装 nginx+mysql+php
阿里云Linux服务器安装 nginx+mysql+php步骤1.登录服务器2.下载安装包3.将安装包上传到服务器的/home目录下 注:使用rz sz命令进行本地和服务器间的上传.下载,安装命令yu ...
- asp.net(c#)中相对路径(虚拟路径)和物理磁盘路径的转换
物理路径:磁盘路径,也就是在磁盘上的位置. 虚拟路径:web页面上的路径,是相对于应用程序而言的. /// 将物理路径转换成相对路径 /// </summary> ...
- 工作目录与os.getcwd()
假设某程序在/root/a/aa.py,在shell,当前pwd为/root,输入./a/aa.py运行py程序,则爱程序的工作目录是/root.而不是程序所在文件夹,os.getcwd()就是查看工 ...
- ipython的%matplotlib inline如何改写在Python
ipython notebook中有一个相当方便的语句: %matplotlib inline,可以实现运行cell即出现结果图像.但是如果想写在Python程序内,貌似直接%matplotlib i ...
- Javascript - 操作符
操作符(Operator) void 如果void后是数字,就返回NAN,否则返回Undefined. alert(void "hello");//跟的字符 print undef ...
- lucene删除索引——(五)
增加在入门程序创建索引中,增删改用IndexWriter. 1.获取IndexWriter的代码 // public IndexWriter getIndexWriter() throws Excep ...
- 云计算--hbase shell
具体的 HBase Shell 命令如下表 1.1-1 所示: 下面我们将以“一个学生成绩表”的例子来详细介绍常用的 HBase 命令及其使用方法. 这里 grad 对于表来说是一个列,course ...
- wpf 自定义控件展开popup,点击popup之外的部分,popup不能自动关闭
比如textbox点击展开popup,这样popup也是不能自动关闭的.可能是textbox获得了焦点. 可是使用textblock,或者ToggleButton来代替textbox点击展开popup ...
- ERP渠道信息的修改和渠道联系记录(二十三)
用例图: 前端代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Cha ...