22764_CountryRoads

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

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

Pro.ID

22764

Title

Country Roads

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    It will be summer vocation soon. Bob want to go for a trip of his hometown. Assumes that there are N places Bob are interested in. And between any two places (for example, A and B) of them, there're exactly two roads, one from A to B, the other from B to A. Roads could be two types: R1 and R2. People take the bus in R1 roads and walk in R2 roads. Furthermore, Bob's hometown is small in area. Going from A to B, if there is a R2 road between them, it will take you T2 minutes. Or if there is a R1 road from A to B, only T1 minutes is enough. ( Of course, T1 < T2 ).

    You can not go by bus to travel from A, to B, to C, ... and finally return to A. In other words, there's not any cycles C1 -> C2-> ...-> Ck -> C1, that the roads from C1 to C2, from C2 to C3, ... from Ck to C1, are all R1 roads.

    The Information above is something about Bob's hometown. Now Bob is preparing for his summer trip. He wants to go from one place, visit all the interesting places, and return to the original place. Bob will stay at each place T minutes. Bob is busy; please help Bob to minimize the time he has to spend. Smart programmers, figure it out quickly please.

    Here is an example (as Figure 1 shows). There are 4 places in (a), and (b) is one of the optimal schedules ( A -> B -> C -> D -> A ). Solid lines are R1 roads, and the dot lines are R2 roads.

    According to (b), Bob has to spend T + T1 + T + T2 + T + T1 + T + T2 = 4T + 2T1 + 2T2 minutes.

    ( a )                                                         ( b )

    Figure 1  The Country Roads

    输入

    The first line of the input is a positive integer C. C is the number of the test cases followed.

    Each test case contains two parts. First part are four integer N ( 1 < N < 100 ), T, T1, T2 ( 0 < T, T1, T2 < 100 ). The second part is a N×N matrix M. Bob have to spend M[i][j] minutes to go from place i to places j. As the problem statement, if i=j, M[i][j]=0; otherwise, M[i][j] is equal to T1 or T2 ( T1 < T2 ). There may be one or several spaces before or after the integers. All integers in the input file is smaller than 1000.

    输出

    Description

    It will be summer vocation soon. Bob want to go for a trip of his hometown. Assumes that there are N places Bob are interested in. And between any two places (for example, A and B) of them, there're exactly two roads, one from A to B, the other from B to A. Roads could be two types: R1 and R2. People take the bus in R1 roads and walk in R2 roads. Furthermore, Bob's hometown is small in area. Going from A to B, if there is a R2 road between them, it will take you T2 minutes. Or if there is a R1 road from A to B, only T1 minutes is enough. ( Of course, T1 < T2 ).

    You can not go by bus to travel from A, to B, to C, ... and finally return to A. In other words, there's not any cycles C1 -> C2-> ...-> Ck -> C1, that the roads from C1 to C2, from C2 to C3, ... from Ck to C1, are all R1 roads.

    The Information above is something about Bob's hometown. Now Bob is preparing for his summer trip. He wants to go from one place, visit all the interesting places, and return to the original place. Bob will stay at each place T minutes. Bob is busy; please help Bob to minimize the time he has to spend. Smart programmers, figure it out quickly please.

    Here is an example (as Figure 1 shows). There are 4 places in (a), and (b) is one of the optimal schedules ( A -> B -> C -> D -> A ). Solid lines are R1 roads, and the dot lines are R2 roads.

    According to (b), Bob has to spend T + T1 + T + T2 + T + T1 + T + T2 = 4T + 2T1 + 2T2 minutes.

    ( a )                                                         ( b )

    Figure 1  The Country Roads

    Input

    The first line of the input is a positive integer C. C is the number of the test cases followed.

    Each test case contains two parts. First part are four integer N ( 1 < N < 100 ), T, T1, T2 ( 0 < T, T1, T2 < 100 ). The second part is a N×N matrix M. Bob have to spend M[i][j] minutes to go from place i to places j. As the problem statement, if i=j, M[i][j]=0; otherwise, M[i][j] is equal to T1 or T2 ( T1 < T2 ). There may be one or several spaces before or after the integers. All integers in the input file is smaller than 1000.

    Output

    The output of the program should consist of one line of output for each test case.

    The output of each test case only contains an integer S. S is the minimum time Bob has to spend. No any redundant spaces are needed.

    Sample Input

    1
    4 10 10 20
    0 10 10 10
    20 0 20 20
    20 20 0 10
    20 20 20 0

    Sample Output

    100

    Source

    样例输入

    1
    4 10 10 20
    0 10 10 10
    20 0 20 20
    20 20 0 10
    20 20 20 0

    样例输出

    100

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部