##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
You are given intervals. The -th interval is represented by .
We construct an undirected graph with vertices, where each vertex represents one of the intervals. There is an edge between vertex and vertex () if and only if their corresponding intervals intersect (i.e., ). The weight of this edge is defined as .
Your task is to find the length of the shortest path from vertex to vertex in this graph. If there is no path between them, output .
The optimal path is to move from the first interval to the second interval (with a cost of ), and then from the second interval to the fourth interval (with a cost of ). The total cost is .
To reach the fifth interval, the path must go through all intervals sequentially. The path goes from the first interval to the second, then the third, fourth, and finally the fifth. The costs of traversing these edges are , , , and , respectively, resulting in a total cost of .