#include #include #define pb push_back #define mp make_pair #define length first #define identy second #define inf 999999999 using namespace std; //order by larger :D, thus, pair //heap for dijkstra n log n priority_queue< pair > heap; //adjacency list vector< pair > adj[1005]; //weight of each node (the multiplier) double v[1005]; double maxV[1005]; bool used[1005]; int main() { int n, m; int i, j; int instance_counter = 1; while (scanf ("%d", &n) && n != 0) { double l; int id; //making the adjacency list while (!heap.empty()) heap.pop(); for (i = 0; i < n; i++) { adj[i].clear(); used[i] = false; maxV[i] = (double) (-inf); scanf (" %lf %d", &v[i], &m); for (j = 0; j < m; j++) { scanf (" %d %lf", &id, &l); adj[i].pb(mp(l, id)); } } //adding initial node heap.push(mp(v[0], 0)); maxV[0] = v[0]; while (!heap.empty()) { int at = heap.top().identy; heap.pop(); while (used[at] == true && !heap.empty()) { at = heap.top().identy; heap.pop(); } if (used[at] == true) break; used[at] = true; for (i = 0; i < adj[at].size(); i++) { if (maxV[adj[at][i].identy] < maxV[at] * adj[at][i].length * v[adj[at][i].identy]) { maxV[adj[at][i].identy] = maxV[at] * adj[at][i].length * v[adj[at][i].identy]; heap.push(mp(maxV[adj[at][i].identy], adj[at][i].identy)); } } } printf("Network %d: %.2lf\n", instance_counter++, maxV[n-1]); } return 0; }