#include #include #include using namespace std; struct Node { int index; // paths info vector to; vector cost; // Dijkstra-related bool done; int c; // cost int from; bool operator>(const Node &a) const { if (c != a.c) { return (c > a.c); } return (index > a.index); } }; int main() { int n; int casenum = 0; while (cin >> n, n) { casenum++; Node nodes[11]; for (int i=1; i<=n; i++) { nodes[i].index = i; int m; cin >> m; for (int j=0; j> to >> cost; nodes[i].to.push_back(to); nodes[i].cost.push_back(cost); } nodes[i].done = false; nodes[i].c = -1; } int start, end; cin >> start >> end; // Dijkstra's shortest path find nodes[start].c = 0; priority_queue, greater > q; q.push(nodes[start]); while ( !q.empty() ) { Node node = q.top(); q.pop(); if (node.done) { continue; } node.done = true; for (int i=0; i path; for (int idx = end; idx != start; idx = nodes[idx].from) { path.push_back(idx); } path.push_back(start); cout << "Case " << casenum << ": Path ="; for (int i=path.size()-1; i>=0; i--) { cout << " " << path[i]; } cout << "; " << nodes[end].c << " second delay" << endl; } return 0; }