记录编号 353679 评测结果 AAAAAAAAA
题目名称 [USACO 2.4.4]回家 最终得分 100
用户昵称 GravatarBokjan 是否通过 通过
代码语言 C++ 运行时间 0.007 s
提交时间 2016-11-18 14:58:30 内存使用 0.32 MiB
显示代码纯文本
#define FOR(i, s, t) for(int i = s; i != t; ++i)
#define ROF(i, s, t) for(int i = s; i != t; --i)
#define REP(i, s, t) for(int i = s; i <= t; ++i)
#define PER(i, s, t) for(int i = s; i >= t; --i)
#define FOREACH(it, c) for(auto it = c.begin(); it != c.end(); ++it)
#define FOREACH_(t, it, c) for(t::iterator it = c.begin(); it != c.end(); ++it)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define FI(x) freopen(x, "r", stdin)
#define FO(x) freopen(x, "w", stdout)
#include <cstdio>
const int MAXN = 80;
const int INF = 0xFFFFFFFF >> 4;
int map[] = 
{
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 1, 2, 3, 4, 5, 6, 7, 
	8, 9, 10, 11, 12, 13, 14, 15,
	16, 17, 18, 19, 20, 21, 22, 23,
	24, 25, 26, 0, 0, 0, 0,
	0, 0, 27, 28, 29, 30, 31, 32,
	33, 34, 35, 36, 37, 38, 39, 40,
	41, 42, 43, 44, 45, 46, 47, 48,
	49, 50, 51, 52, 53, 54, 55, 56
};
int g[MAXN][MAXN];
template <typename T>
void RU(T &x)
{
	x = 0;
	char c = getchar();
	while(c < '0' || c > '9')
		c = getchar();
	while(c >= '0' && c <= '9')
	{
		x = x * 10 + c - '0';
		c = getchar();
	}
}
void Read(void)
{
	FOR(i, 0, MAXN)
	FOR(j, 0, MAXN)
		g[i][j] = INF;
	int p, u, v, w;
	char x[8], y[8];
	RU(p);
	while(p--)
	{
		scanf("%s%s%d", x, y, &w);
		u = map[(size_t)x[0]];
		v = map[(size_t)y[0]];
		if(w < g[u][v])
			g[u][v] = g[v][u] = w;
	}
}
void Solve(void)
{
	REP(k, 1, 56)
	REP(i, 1, 56)
	REP(j, 1, 56)
		if(g[i][k] + g[k][j] < g[i][j])
			g[i][j] = g[i][k] + g[k][j];
	int MinID = 0;
	int endpoint = map[(size_t)'Z'];
	REP(i, 1, 25)
		if(g[MinID][endpoint] > g[i][endpoint])
			MinID = i;
	printf("%c %d\n", (char)(MinID + 'A' - 1), g[MinID][endpoint]);
}
int main(void)
{
	FI("comehome.in");
	FO("comehome.out");
	Read();
	Solve();
	return 0;
}