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 迪杰斯特拉的更多相关文章

  1. 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 ...

  2. 2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229511 时间限制:1s 空间限制:512MB 题目大意: 给定一个n 随后跟着2n行输入 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

随机推荐

  1. the error about “no such file or directory”

    CHENYILONG Blog the error about "no such file or directory" when you get the question like ...

  2. ios TextField限制输入两位小数

    只需要实现textField的这个代理方法就可以实现 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange: ...

  3. js如何用json 读取C#的Dictionary

    1. .net中Controller里面的方法 /// <summary> /// 流程图 /// </summary> /// <returns>返回对象Json ...

  4. pytorch函数之torch.normal()

    Returns a Tensor of random numbers drawn from separate normal distributions who’s mean and standard ...

  5. Windows命令-系统木马取样

    1.前言 工作中偶尔会遇到去现场提取木马样本回公司分析的情况.如果是生产环境下,不方便安装各类抓包.安全软件时.能用系统自带的命令去定位出木马程序相关的信息是最理想不过的状态. 2.Windows常用 ...

  6. 高通Trustzone and QSEE介绍

    http://blog.csdn.net/iamliuyanlei/article/details/52625968

  7. 错误的理解引起的bug async await 执行顺序

    今天有幸好碰到一个bug,让我知道了之前我对await async 的理解有点偏差. 错误的理解 之前我一直以为  await 后面的表达式,如果是直接返回一个具体的值就不会等待,而是继续执行asyn ...

  8. Java编程的逻辑 (36) - 泛型 (中) - 解析通配符

    本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...

  9. #JS 前端javascript规范文档

    一.规范目的 为提高团队协作效率,便于前端后期优化维护,输出高质量的文档. 二.基本准则 符合web标准,结构表现行为分离,兼容性优良.页面性能方面,代码要求简洁明了有序, 尽可能的减小服务器负载,保 ...

  10. koa+orm2

    koa+orm2 koa是由 Express 原班人马打造的新的web框架.套用其官方的说法:Koa 应用是一个包含一系列中间件 generator 函数的对象. 这些中间件函数基于 request ...