比赛 20150422 评测结果 AAAAAAAAAAA
题目名称 背驮式行走 最终得分 100
用户昵称 _Horizon 运行时间 0.052 s
代码语言 C++ 内存使用 5.70 MiB
提交时间 2015-04-22 11:36:09
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>


using namespace std;


int b,e,p,n,m;
struct Edge{
	int to,next;
}edge[100010];
int h[50000],num;
void add(const int&x,const int &y){
	num++;
	edge[num].to=y;
	edge[num].next=h[x];
	h[x]=num;
}
int dist1[50000],dist2[50000],dist3[50000];
const int inf=0x3fffffff;
int que[1000010];
bool book[50000];
void spfa(const int &st,int dist[]){
	for(int i=1;i<=n;i++)dist[i]=inf;
	int head=0,tail=1;
	memset(book,0,sizeof(book));
	book[st]=1;dist[st]=0;
	que[head]=st;
	while(head!=tail){
		int u=que[head];
		for(int i=h[u];i;i=edge[i].next){
			int v=edge[i].to;
			if(dist[v]>dist[u]+1){
				dist[v]=dist[u]+1;
				if(!book[v]){
					que[tail++]=v;
					book[v]=1;
				}
			}
		}
		book[u]=0;
		head++;
	}
}
int main(){
	freopen("piggyback.in","r",stdin);
	freopen("piggyback.out","w",stdout);
	scanf("%d%d%d%d%d",&b,&e,&p,&n,&m);
	int x,y;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	spfa(1,dist1);
	spfa(2,dist2);
	spfa(n,dist3);
	int ans=inf;
	for(int i=1;i<=n;i++){
		ans=min(ans,dist1[i]*b+dist2[i]*e+dist3[i]*p);
	}
	ans=min(ans,dist3[1]*b+dist3[2]*e);
	printf("%d",ans);
	return 0;
}