比赛 |
20150422 |
评测结果 |
AAAAAAAAAAA |
题目名称 |
背驮式行走 |
最终得分 |
100 |
用户昵称 |
Chenyao2333 |
运行时间 |
0.083 s |
代码语言 |
C++ |
内存使用 |
1.68 MiB |
提交时间 |
2015-04-22 08:32:53 |
显示代码纯文本
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
const int L_N=4e4+10;
const LL INF=1ll*1e8*1e8;
//b's start at 1, a's start at 2, p's start at n;
LL d_b[L_N],d_e[L_N],d_p[L_N];
vector<int> G[L_N];
int B,E,P,N,M;
void bfs(int s,int cost,LL d[]){
for(int i=1;i<=N;i++) d[i]=INF;
d[s]=0;
queue<int> q;
q.push(s);
while(q.size()){
int u=q.front(); q.pop();
for(int i=0;i<G[u].size();i++){
int v=G[u][i];
if(d[v]>d[u]+cost){
d[v]=d[u]+cost;
q.push(v);
}
}
}
}
int main(){
freopen("piggyback.in","r",stdin);
freopen("piggyback.out","w",stdout);
scanf("%d %d %d %d %d",&B,&E,&P,&N,&M);
for(int i=1;i<=M;i++){
int u,v; scanf("%d %d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
bfs(1,B,d_b);
bfs(2,E,d_e);
bfs(N,P,d_p);
LL ans=INF;
for(int i=1;i<=N;i++){
ans=min(ans,d_b[i]+d_e[i]+d_p[i]);
}
printf("%lld\n",ans);
return 0;
}