Gremlins have infested the farm. These nasty, fairy-like creatures love to harass the cows. Every cow starts at the barn, conveniently located at pasture $1$, and walks to its own field: cow $i$ travels from pasture $1$ to pasture $i$.
Each gremlin knows the unique shortest route its cow normally takes. Gremlin $i$ waits in the middle of the last road of the shortest route from pasture $1$ to pasture $i$, hoping to harass cow $i$.
To avoid being harassed, each cow $i$ instead picks the fastest route from pasture $1$ (the barn) to pasture $i$ that does not use that last road of its shortest route. For every cow $i$, compute the shortest possible time of such a route that avoids the road guarded by gremlin $i$.
For example, consider the following pastures and roads (numbers in brackets are traversal times):
1--[2]--2-------+
| | |
[2] [1] [3]
| | |
+-------3--[4]--4
Without gremlins, the shortest routes are:
| Trip | Best route | Best time | Last road |
|---|---|---|---|
| 1 → 2 | 1→2 | 2 | 1→2 |
| 1 → 3 | 1→3 | 2 | 1→3 |
| 1 → 4 | 1→2→4 | 5 | 2→4 |
When each gremlin guards the last road of its cow's shortest route, the best routes that avoid those roads are:
| Trip | New route | New best time | Road to avoid |
|---|---|---|---|
| 1 → 2 | 1→3→2 | 3 | 1→2 |
| 1 → 3 | 1→2→3 | 3 | 1→3 |
| 1 → 4 | 1→3→4 | 6 | 2→4 |