21620_Trave

2022-5-16 18:19| 发布者: Hocassian| 查看: 36| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505696274399-Problem List-采集的数据-后羿采集器.html

Pro.ID

21620

Title

Travel

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21620

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    One day TZD wants to go from village 0 to village n-1. There are m directed roads connecting the n villages. There may be more than one road from a village to another village.

    When he travels between villages in the same strongly connected component, he can rent a bike. Otherwise, he has to walk. More precisely, for each road from village a to village b, if the two villages are in the same strongly connected component (meaning that you can go from village a to village b and also from village b to village a) then you can rent a bike and travel through the road in time[a][b] minutes. Otherwise you have to travel through it on foot in 2*time[a][b] minutes.

    TZD wants to get to his destination as quickly as possible and he expects that the number of roads he travels on foot is no more than k. Now you are asked to find the shortest time that TZD can reach his destination with the number of roads he travels on foot no more than k.

    输入

    The input may contain several test cases.

    Each test case starts with a line containing three integer n, m and k. Each is described above. ( 1 ≤ n ≤ 100,  0 ≤ m ≤ 100000,  0 ≤ k ≤ 10 ).

    The next m lines each contain three integer a, b and time[a][b], meaning that there is a road from village a to village b and it takes time[a][b] minutes to travel through the road by bike, 2*time[a][b] minutes on foot. ( 0 ≤ a, bn-1,  0 < time[a][b] ≤ 10000 )

    Input is terminated by one line contains three zeros.

    输出

    Description

    One day TZD wants to go from village 0 to village n-1. There are m directed roads connecting the n villages. There may be more than one road from a village to another village.

    When he travels between villages in the same strongly connected component, he can rent a bike. Otherwise, he has to walk. More precisely, for each road from village a to village b, if the two villages are in the same strongly connected component (meaning that you can go from village a to village b and also from village b to village a) then you can rent a bike and travel through the road in time[a][b] minutes. Otherwise you have to travel through it on foot in 2*time[a][b] minutes.

    TZD wants to get to his destination as quickly as possible and he expects that the number of roads he travels on foot is no more than k. Now you are asked to find the shortest time that TZD can reach his destination with the number of roads he travels on foot no more than k.

    Input

    The input may contain several test cases.

    Each test case starts with a line containing three integer n, m and k. Each is described above. ( 1 ≤ n ≤ 100,  0 ≤ m ≤ 100000,  0 ≤ k ≤ 10 ).

    The next m lines each contain three integer a, b and time[a][b], meaning that there is a road from village a to village b and it takes time[a][b] minutes to travel through the road by bike, 2*time[a][b] minutes on foot. ( 0 ≤ a, bn-1,  0 < time[a][b] ≤ 10000 )

    Input is terminated by one line contains three zeros.

    Output

    For each test case print the answer in a single line. If TZD can't get to his destination with the number of roads he travels on foot no more than k, print -1.

    Sample Input

    5 6 3
    0 1 1
    0 2 2
    2 1 1
    1 3 3
    3 1 3
    3 4 2
    0 0 0

    Sample Output

    9

    Source

    样例输入

    5 6 3
    0 1 1
    0 2 2
    2 1 1
    1 3 3
    3 1 3
    3 4 2
    0 0 0

    样例输出

    9

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部