比赛 20150422 评测结果 AAAAAAAAAAA
题目名称 背驮式行走 最终得分 100
用户昵称 Asm.Def 运行时间 0.099 s
代码语言 C++ 内存使用 1.68 MiB
提交时间 2015-04-22 08:51:23
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <cmath>
using namespace std;
//#define USEFREAD
#ifdef USEFREAD
#define InputLen 5000000
char *ptr=(char *)malloc(InputLen);
#define getc() (*(ptr++))
#else
#define getc() (getchar())
#endif
#define SetFile(x) (freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout))
template<class T>inline void getd(T &x){
	int ch = getc();bool neg = false;
	while(!isdigit(ch) && ch != '-')ch = getc();
	if(ch == '-')ch = getc(), neg = true;
	x = ch - '0';
	while(isdigit(ch = getc()))
		x = x * 10 - '0' + ch;
	if(neg)x = -x;
}
/***********************************************************************/
const int maxn = 40005;
typedef long long LL;
int B, E, P, N, M;
#include <vector>
#include <queue>
vector<int> adj[maxn];
int vis[3][maxn], dis[3][maxn];

inline void BFS(int id, int cur){
	static queue<int> Q;
	Q.push(cur);vis[id][cur] = true;
	int t, *dist = dis[id];
	vector<int>::iterator it;
	while(!Q.empty()){
		t = Q.front();Q.pop();
		int d = dist[t];
		for(it = adj[t].begin();it != adj[t].end();++it)if(!vis[id][*it]){
			dist[*it] = d + 1;
			vis[id][*it] = true;
			Q.push(*it);
		}
	}
}

inline void init(){
	getd(B), getd(E), getd(P), getd(N), getd(M);
	int a, b;
	while(M--){
		getd(a), getd(b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	BFS(0, 1);BFS(1, 2);BFS(2, N);
}

int main(){
	#ifdef DEBUG
	freopen("test.txt", "r", stdin);
	#else       
	SetFile(piggyback);
	#endif
	#ifdef USEFREAD
	fread(ptr,1,InputLen,stdin);
	#endif
	
	LL ans = 0x7fffffffffffffffll, tmp;
	init();
	for(int i = 1;i <= N;++i){
		tmp = 0;
		tmp += B * dis[0][i];
		tmp += E * dis[1][i];
		tmp += P * dis[2][i];
		ans = min(tmp, ans);
	}
	printf("%lld\n", ans);
	
#ifdef DEBUG
    printf("\n%.3lf sec \n", (double)clock() / CLOCKS_PER_SEC);
#endif
    return 0;
}