Festival 3 - MarisaOJ: Marisa Online Judge

Festival 3

Time limit: 1000 ms
Memory limit: 256 MB
Today is the joyous Tanabata day, and Reimu is preparing to host a festival at Hakurei Shrine. Excited to join in the festivities, Marisa decides to make the day even more memorable by purchasing a sake bottle as a special gift. There are a total of n unique places where Marisa can buy sake, each with its own price denoted by ci. To navigate between these places, Marisa can utilize a special two-way transportation system operated by the Kappa. However, there are certain costs associated with using each route. The first time Marisa uses route i, it incurs a cost of wi. However, due to the system's unique rules, subsequent uses of the same route will be free. Marisa devises a plan to begin her journey from her house at location 1, explore different places to find the perfect sake, and ultimately reach the Hakurei Shrine located at location n. The goal is to determine the minimum cost for Marisa to accomplish her plan and fully enjoy the Tanabata festival. ### Input - The first line contains two integer n,m. - The second line contains n integer ci. - The next m lines, each line contains three integer u,v,w, there is a route between u and v and costs wi for the first time. ### Output - Print an integer, the minimum cost. ### Constraints - 1≤n,m≤105. - 1≤u,v≤n,u≠v. - 1≤wi,ci≤109. ### Example Input: 56101011010122231341452151252 Output: 5