#include<stdio.h> int main() { int n, t; int a, b, value; int w, e; int c, d; int count = 0; while (scanf("%d %d", &n, &t) != EOF && !(n == 0 && t == 0)) { int x[200][200] = { 0 }; int y[200][200] = { 0 }; int sum = 0; int res = 0; while (t--) { scanf("%d %d %d", &a, &b, &value); if (value < x[a][b]||x[a][b]==0) { x[a][b] = value; } if (value < x[b][a] || x[b][a] == 0) { x[b][a] = value; } } scanf("%d %d", &w, &e); while (w--) { scanf("%d %d", &c, &d); if (!y[c][d]) { y[c][d] = 1; y[d][c] = 1; sum += x[c][d]; } if (d == e) { res = sum; } } count++; printf("Case #%d: %d\n", count, res); } } |
Double click to view unformatted code.