##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
5 2 1 1 2 3 2 1 2 2 3 3 3 1 2 2 3 1 3 4 4 1 2 2 3 3 4 4 1 5 5 1 2 2 3 3 4 4 5 5 1
Sample: path (1,2), path (2), triangle (-1), square (1), pentagon (-1)
1 2 -1 1 -1
You are given a connected undirected graph with vertices and edges. You want to assign a direction to every edge.
After fixing an orientation, each undirected edge becomes either or . Traversing an edge has cost:
A path from to is allowed to be any walk: vertices and edges may repeat, and the walk may traverse the same edge multiple times. The cost of a walk is the sum of the costs of its traversed edges.
For a fixed orientation, define the shortest-path value as the minimum possible walk cost from vertex to vertex (over all walks).
Among all orientations, choose one that maximizes this shortest-path value. Output this maximum value.
If for every orientation the shortest-path value is (i.e., for every orientation there exist walks from to with arbitrarily small total cost), output .
Where for each test case: