##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
2 1 1 2 5
0
3 4 1 2 3 2 3 4 1 3 10 1 3 9
3
You are given a directed graph with vertices and directed edges.
Each directed edge has an integer weight .
If you traverse an edge in its given direction , the cost is .
If you traverse it in the opposite direction , the cost is .
For any walk, its cost is the sum of costs of its steps.
Define as the minimum possible cost among all walks from to .
We say the graph is good if it has no negative closed walk, meaning there is no walk that starts and ends at the same vertex with total cost .
Equivalently, the graph is good iff for every vertex , we have .
In one operation, you may choose one directed edge and do one of the following:
Find the minimum number of operations needed to make the graph good.
No change is needed, so the minimum number of operations is .
Set the weights to:
This needs operation on , operation on , and operation to change the edge from to , so the total is .