想说:什么破题目描述。
自环!? 从A -> a 距离是100的话,a -> C 距离是50. 那么 那么A->C距离是150 !
题目需要把A和a看成是2个截然不同的点!然后直接做最短路即可。 这题目描述我看的也是醉了……
Test 1: TEST OK [0.003 secs, 3404 KB] Test 2: TEST OK [0.003 secs, 3404 KB] Test 3: TEST OK [0.005 secs, 3404 KB] Test 4: TEST OK [0.003 secs, 3404 KB] Test 5: TEST OK [0.003 secs, 3404 KB] Test 6: TEST OK [0.005 secs, 3404 KB] Test 7: TEST OK [0.016 secs, 3404 KB] Test 8: TEST OK [0.003 secs, 3404 KB] Test 9: TEST OK [0.003 secs, 3404 KB] All tests OK.
/* TASK:comehome LANG:C++ */ #include <iostream> #include <cstring> #include <cstdio> using namespace std; int n; int f[100][100]; bool cow[26]={0}; int check(char ch) { if ('A' <= ch && ch <= 'Z') return ch - 'A' + 26; else return ch - 'a'; } void init() { int n, tmp; scanf("%d",&n); memset(f, 50, sizeof(f)); while (n--) { getchar(); int X = check(getchar()); getchar(); int Y = check(getchar()); scanf("%d", &tmp); //cout<<X<<" "<<Y<<" "<<tmp<<endl; f[X][Y] = f[Y][X] = min(f[X][Y], tmp); } } void doit() { for (int k = 0; k != 52; ++ k) for (int i = 0; i != 52; ++ i) for (int j =0; j != 52; ++ j) if (f[i][j] > f[i][k] + f[k][j]) f[i][j] = f[j][i] = f[i][k] + f[k][j]; int wz, ans=0x7fffffff; for (int i = 26; i != 51; ++ i) if (f[51][i] < ans) { ans = f[51][i]; wz = i - 26; } cout<< char(wz + 'A') <<" "<<ans<<endl; } int main() { freopen("comehome.in","r",stdin); freopen("comehome.out","w",stdout); init(); doit(); return 0; }