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. 那些年的 网络通信之 UDP 数据报包传输---

    下面是 一个多线程,基于 UDP 用户数据报包 协议 的 控制台聊天小程序 import java.io.*; import java.net.*; class Send implements Run ...

  2. .NET面试题系列(四)计算机硬件知识

    计算机的硬件组成 总线:贯穿整个系统的是一组电子管道(其实就是传输数据的线路),也就是总线.总线传送的是字,字的大小与系统相关,比如在32位操作系统当中, 一个字是4个字节. I/O设备:I/O设备是 ...

  3. 【原创】backbone1.1.0源码解析之Model

    趁热打铁,将Backbone.Model的源代码注释也发出来. Model是用来干嘛的?写过mvc的同学应该都知道,说白了就是model实例用来存储数据表中的一行数据(row) Backbone利用m ...

  4. Tju_Oj_3988Password

    这个题是给树的前序和中序,输出后序. 做法是根据前序找根,根据根在中序中找中序的左右子树,根据左右子树长度找前序的左右子树,依此递归. 做过之后感觉还是比较基础的,废话不多说,上题上代码. Bob w ...

  5. Manacher's Algorithm 马拉车算法

    作用:求一个字符串中的最长子串,同时还可以求所有子串的长度. 题目链接: https://vjudge.net/contest/254692#problem/B 代码: #include<bit ...

  6. 利用gcc自带的功能-fstack-protector检测栈溢出及其实现【转】

    转自:https://www.cnblogs.com/leo0000/p/5719186.html 最近又遇到了一个崩溃,栈回溯非常怪异. /lib/i386-linux-gnu/libc.so.6( ...

  7. 苹果ANCS协议学习【转】

    苹果ANCS协议学习 转自:http://www.cnblogs.com/alexcai/p/4321514.html 综述 苹果通知中心(Apple Notification Center Serv ...

  8. ubuntu12.04安装maven

    step: 1,确认已经安装jdk, java --version 2,下载apache-maven-3.3.9 下载地址:http://maven.apache.org/download.cgi 3 ...

  9. django之class Meta

    通过一个内嵌类 "class Meta" 给你的 model 定义元数据, 类似下面这样: class Foo(models.Model): bar = models.CharFi ...

  10. P4186 【[USACO18JAN]Cow at Large G】

    思路是覆盖子树,我们发现,农民想截住牛的最优策略是不断向上来尽可能地覆盖更大的子树 我们想要尽早地覆盖一个子树,一个显然的贪心是在这个子树中选取深度最小的一个放农民 如果我们在一个点放置了农民,那么其 ...