CF1915G.Bicycles

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

All of Slavic's friends are planning to travel from the place where they live to a party using their bikes. And they all have a bike except Slavic. There are nn cities through which they can travel. They all live in the city 11 and want to go to the party located in the city nn . The map of cities can be seen as an undirected graph with nn nodes and mm edges. Edge ii connects cities uiu_i and viv_i and has a length of wiw_i .

Slavic doesn't have a bike, but what he has is money. Every city has exactly one bike for sale. The bike in the ii -th city has a slowness factor of sis_{i} . Once Slavic buys a bike, he can use it whenever to travel from the city he is currently in to any neighboring city, by taking wisjw_i \cdot s_j time, considering he is traversing edge ii using a bike jj he owns.

Slavic can buy as many bikes as he wants as money isn't a problem for him. Since Slavic hates traveling by bike, he wants to get from his place to the party in the shortest amount of time possible. And, since his informatics skills are quite rusty, he asks you for help.

What's the shortest amount of time required for Slavic to travel from city 11 to city nn ? Slavic can't travel without a bike. It is guaranteed that it is possible for Slavic to travel from city 11 to any other city.

输入格式

The first line contains a single integer tt ( 1t1001 \leq t \leq 100 ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two space-separated integers nn and mm ( 2n10002 \leq n \leq 1000 ; n1m1000n - 1 \leq m \leq 1000 ) — the number of cities and the number of roads, respectively.

The ii -th of the following mm lines each contain three integers uiu_i , viv_i , wiw_i ( 1ui,vin1 \le u_i, v_i \le n , uiviu_i \neq v_i ; 1wi1051 \leq w_i \leq 10^5 ), denoting that there is a road between cities uiu_i and viv_i of length wiw_i . The same pair of cities can be connected by more than one road.

The next line contains nn integers s1,,sns_1, \ldots, s_n ( 1si10001 \leq s_i \leq 1000 ) — the slowness factor of each bike.

The sum of nn over all test cases does not exceed 10001000 , and the sum of mm over all test cases does not exceed 10001000 .

Additional constraint on the input: it is possible to travel from city 11 to any other city.

输出格式

For each test case, output a single integer denoting the shortest amount of time Slavic can reach city nn starting from city 11 .

输入输出样例

  • 输入#1

    3
    5 5
    1 2 2
    3 2 1
    2 4 5
    2 5 7
    4 5 1
    5 2 1 3 3
    5 10
    1 2 5
    1 3 5
    1 4 4
    1 5 8
    2 3 6
    2 4 3
    2 5 2
    3 4 1
    3 5 8
    4 5 2
    7 2 8 4 1
    7 10
    3 2 8
    2 1 4
    2 5 7
    2 6 4
    7 1 2
    4 3 5
    6 4 2
    6 7 1
    6 7 4
    4 5 9
    7 6 5 4 3 2 1

    输出#1

    19
    36
    14
首页