Under construction

Still being built. Things may change

"Shortest" Pair of Paths

Time limit1sMemory limit128 MB

Summary
Find two vertex-disjoint (except endpoints) and edge-disjoint directed paths from node 0 to node N-1 minimizing total cost, or report impossibility.
Level

Hard8 of 10

Topics
Graph, Shortest path, Minimum spanning tree
Solved
No attempts yet

Problem

A chemical company has an unusual shortest path problem.

There are NN depots (vertices) where chemicals can be stored, and MM individual shipping methods (edges) connecting pairs of depots. Each individual shipping method has a cost. In the usual problem, the company would need only to route a single shipment from the first depot (00) to the last (N−1N - 1); that is easy. The problem they have is harder: they have to ship two chemicals from the first depot (00) to the last (N−1N - 1). The chemicals are dangerous and cannot safely be placed together. The regulations say the company cannot use the same shipping method for both chemicals. Further, the company cannot place the two chemicals in the same depot (for any length of time) without special storage handling, which is available only at the first and last depots.

To begin, they need to know whether it is possible to ship both chemicals under these constraints. Next, they need to find the least cost of shipping both chemicals from the first depot to the last depot. In brief, they need two completely separate paths (from the first depot to the last) where the overall cost of both is minimal.

Your program must simply determine the minimum cost or, if it is not possible, conclusively state that the shipment cannot be made.

Input

The input consists of multiple cases. The first line of each case contains NN and MM, where NN is the number of depots and MM is the number of individual shipping methods. You may assume that NN is less than 6464 and that MM is less than 1000010000. The next MM lines each contain three values, ii, jj, and vv. Each line corresponds to a single, unique shipping method. The values ii and jj are the indices of two depots, and vv is the (non-negative integer) cost of getting from ii to jj. Note that these shipping methods are directed: if something can be shipped from ii to jj with cost 1010, that says nothing about shipping from jj to ii. Also, there may be more than one way to ship between any pair of depots, and that may be important here. A line containing two zeroes signals the end of the data and should not be processed.

Output

For each case, print one line in the form Instance #k: C, where kk is the case number (starting from 11) and CC is the minimum total cost of shipping both chemicals. If the shipment cannot be made, print Instance #k: Not possible instead. Note that there are two spaces after the colon.

Examples1

  1. Example 1

    Input
    2 1
    0 1 20
    2 3
    0 1 20
    0 1 20
    1 0 10
    4 6
    0 1 22
    1 3 11
    0 2 14
    2 3 26
    0 3 43
    0 3 58
    0 0 0
    
    Expected output
    Instance #1:  Not possible
    Instance #2:  40
    Instance #3:  73