首页 > 其他 > 详细

【Codeforces 707B】Bakery 水题

时间:2016-08-21 19:47:14      阅读:300      评论:0      收藏:0      [点我收藏+]

对每个storages找一下最短的相邻边

#include <cstdio>
#define N 100005
#define inf 0x3f3f3f3f
using namespace std;
struct edge{
	int to,next,w;
}e[N<<1];
int head[N],cnt;
void add(int u,int v,int w){
	e[++cnt]=(edge){v,head[u],w};
	head[u]=cnt;
}
int n,m,k;
int st[N];
int main() {
	scanf("%d%d%d",&n,&m,&k);
	int ok=0;
	for(int i=1;i<=m;i++)
	{
		int u,v,l;
		scanf("%d%d%d",&u,&v,&l);
		add(v,u,l);
		add(u,v,l);
	}
	for(int i=1;i<=k;i++){
		int x;
		scanf("%d",&x);
		st[x]=1;
	}
	int ans=inf;
	for(int i=1;i<=n;i++)
		if(st[i])
			for(int j=head[i];j;j=e[j].next)
				if(st[e[j].to]==0&&e[j].w<ans)
					ans=e[j].w;
	if(ans!=inf)printf("%d",ans);
	else printf("-1");
}

  

【Codeforces 707B】Bakery 水题

原文:http://www.cnblogs.com/flipped/p/5793209.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!