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 ...
随机推荐
- dedecms在linux上安装提示没权限解决办法
web服务器运行的用户与目录所有者用户必须不一样,比如apache运行的用户为root,那么网站目录设置的所有者就应该不能设置为root,而是设置不同于root的用户,如apache. 我们这里假设w ...
- Sublime Text 之运行 js 方法[2015-5-6更新mac下执行js]
昨天说完<Sublime Text 2 绿化与汉化 [Windows篇]>,今天我们来说说怎么用st直接运行 js 吧.群里的小伙伴一直对我的 ST 能直接运行js感到非常好奇,今天我就公 ...
- 通俗易懂之Tensorflow summary类 & 初识tensorboard
前面学习的cifar10项目虽小,但却五脏俱全.全面理解该项目非常有利于进一步的学习和提高,也是走向更大型项目的必由之路.因此,summary依然要从cifar10项目说起,通俗易懂的理解并运用sum ...
- 第6月第4天 AVMutableComposition AVMutableVideoComposition
1. AVMutableComposition is a mutable subclass of AVComposition you use when you want to create a new ...
- PyQT5 No module named ‘PyQt5.QtWebEngineWidgets’
PyQT5查找不到模块QtWebEngineWidgets pip install pyqt5==5.10.1 或 安装64位的Pyhon解释器
- 关于gb2312编码和utf8码的一个问题
ANSI(注意拼写不是ASCII)并不是“一种”编码,而是“多种”编码的统称.在简体中文Windows上,ANSI指GBK编码:在繁体中文Windows上,ANSI指Big5编码:在英文Windows ...
- 用Python连接SQLServer抓取分析数据、监控 (pymssql)
Python 环境:python3 服务器环境: centos6.5 数据库: Mysql 大概流程:在装有Python服务器,利用pymssql库连接MSSQL生产数据库取出数据然后写进mysql数 ...
- elasticsearch常用配置
允许外网连接network.host,http.port,network.publish_host,network.bind_host别的机器或者网卡才能访问,否则只能是127.0.0.1或者loca ...
- elasticsearch安装ik分词器(非极速版)
1.下载下载地址为: https://github.com/medcl/elasticsearch-analysis-ik 2.解压把下载的 elasticsearch-analysis-ik.zip ...
- Android 7.0 行为变更
Android 7.0 除了提供诸多新特性和功能外,还对系统和 API 行为做出了各种变更.本文重点介绍您应该了解并在开发应用时加以考虑的一些主要变更. 如果您之前发布过 Android 应用,请注意 ...