21906_Connectionsbetweencities

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

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

Pro.ID

21906

Title

Connections between cities

Title链接

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

AC

15

Submit

83

Ratio

18.07%

时间&空间限制

  • Time Limit: 8000/4000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    After World War X, a lot of cities have been seriously damaged, and we need to rebuild those cities. However, some materials needed can only be produced in certain places. So we need to transport these materials from city to city. For most of roads had been totally destroyed during the war, there might be no path between two cities, no circle exists as well.

    Now, your task comes. After giving you the condition of the roads, we want to know if there exists a path between any two cities. If the answer is yes, output the shortest path between them.

    输入

    Input consists of multiple problem instances.For each instance, first line contains three integers n, m and c, 2 ≤ n ≤ 10000, 0 ≤ m < 10000, 1 ≤ c ≤ 1000000. n represents the number of cities numbered from 1 to n. Following m lines, each line has three integers i, j and k, represent a road between city i and city j, with length k. Last c lines, two integers i, j each line, indicates a query of city i and city j.

    输出

    Description

    After World War X, a lot of cities have been seriously damaged, and we need to rebuild those cities. However, some materials needed can only be produced in certain places. So we need to transport these materials from city to city. For most of roads had been totally destroyed during the war, there might be no path between two cities, no circle exists as well.

    Now, your task comes. After giving you the condition of the roads, we want to know if there exists a path between any two cities. If the answer is yes, output the shortest path between them.

    Input

    Input consists of multiple problem instances.For each instance, first line contains three integers n, m and c, 2 ≤ n ≤ 10000, 0 ≤ m < 10000, 1 ≤ c ≤ 1000000. n represents the number of cities numbered from 1 to n. Following m lines, each line has three integers i, j and k, represent a road between city i and city j, with length k. Last c lines, two integers i, j each line, indicates a query of city i and city j.

    Output

    For each problem instance, one line for each query. If no path between two cities, output "Not connected", otherwise output the length of the shortest path between them.

    Sample Input

    5 3 2
    1 3 2
    2 4 3
    5 2 3
    1 4
    4 5

    Sample Output

    Not connected
    6

    Hint

    Huge input, scanf recommended.

    Source

    样例输入

    5 3 2
    1 3 2
    2 4 3
    5 2 3
    1 4
    4 5

    样例输出

    Not connected
    6

    提示

    Huge input, scanf recommended.


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部