#define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> using namespace std; struct element { int distant=0; bool flag=false;//标记这段距离是否走过 }; int main() { int n, t; int id = 1; while (true) { cin >> n >> t; if (n == 0 && t == 0)break; element arr[3000]; int prea=0 ; int preb=0 ; int prevalue=0; for (int i = 0; i < t; i++) { int a, b, value; cin >> a >> b >> value; element e; if (prea == a && preb == b) { if (value < prevalue) { e.distant = value; arr[b] = e; } } else { e.distant = value; arr[b] = e; } prea = a, preb = b,prevalue=value; } int w, e; cin >> w >> e; int sum = 0; bool tag=false; for (int i = 0; i < w; i++) { int c, d; cin >> c >> d; if (!tag) { if (arr[d].flag == false) { sum += arr[d].distant; arr[c].flag = true; arr[d].flag = true; } } if (d == e)tag=true; } printf("Case #%d: %d\n", id++, sum); } return 0; } |
Double click to view unformatted code.