Colors
Grindra finds themself in a directed graph of nodes and edges. Furthermore, each node is painted a color, initially "Red". As Grindra is in possession of a paintbrush, they are also able to paint the nodes.
Each edge is of the form a b c d e
, meaning that if Grinda is at node when it is painted color , they can paint node color , and the move to it with cost .
As Grindra's painting companion, can you help them answer the question: What is the minimum cost with which they can move from node to node .
Input Format
The first line will consist of two integers, and . The next lines will each consist of 5 integers a b c d e
, as described above.
Output Format
A single integer, the smallest cost to get from node to node , assuming that every node starts as red.
Example Input 1
5 5
0 Red 1 Red 10
1 Red 2 Blue 10
0 Green 2 Blue 5
2 Blue 4 Green 5
1 Red 4 Blue 5
Example Output 1
10
Example Explanation 1
The optimal path is from (0, Red) to (2,Blue) to (4,Green). This has cost 10.
Constraints
Comments