10148_BessieComeHome

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

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

Pro.ID

10148

Title

Bessie Come Home

Title链接

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

AC

28

Submit

63

Ratio

44.44%

时间&空间限制

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

    It's dinner time, and the cows are out in their separate pastures. Farmer John rings the bell so they will start walking to the barn. Your job is to figure out which one cow gets to the barn first (the supplied test data will always have exactly one fastest cow).

    Between milkings, each cow is located in her own pasture, though some pastures have no cows in them. Each pasture is connected by a path to one or more other pastures (potentially including itself). Sometimes, two (potentially self-same) pastures are connected by more than one path. One or more of the pastures has a path to the barn. Thus, all cows have a path to the barn and they always know the shortest path. Of course, cows can go either direction on a path and they all walk at the same speed.

    The pastures are labeled 'a'..'z' and 'A'..'Y'. One cow is in each pasture labeled with a capital letter. No cow is in a pasture labeled with a lower case letter. The barn's label is 'Z'; no cows are in the barn, though.

    输入

    Line 1:   Integer P (1 ≤ P ≤ 10000) the number of paths that interconnect the pastures (and the barn)

    Line 2..P+1:  Space separated, two letters and an integer: the names of the interconnected pastures/barn and the distance between them (1 ≤ distance ≤ 1000)

    输出

    Description

    It's dinner time, and the cows are out in their separate pastures. Farmer John rings the bell so they will start walking to the barn. Your job is to figure out which one cow gets to the barn first (the supplied test data will always have exactly one fastest cow).

    Between milkings, each cow is located in her own pasture, though some pastures have no cows in them. Each pasture is connected by a path to one or more other pastures (potentially including itself). Sometimes, two (potentially self-same) pastures are connected by more than one path. One or more of the pastures has a path to the barn. Thus, all cows have a path to the barn and they always know the shortest path. Of course, cows can go either direction on a path and they all walk at the same speed.

    The pastures are labeled 'a'..'z' and 'A'..'Y'. One cow is in each pasture labeled with a capital letter. No cow is in a pasture labeled with a lower case letter. The barn's label is 'Z'; no cows are in the barn, though.

    Input

    Line 1:   Integer P (1 ≤ P ≤ 10000) the number of paths that interconnect the pastures (and the barn)

    Line 2..P+1:  Space separated, two letters and an integer: the names of the interconnected pastures/barn and the distance between them (1 ≤ distance ≤ 1000)

    Output

    A single line containing two items: the capital letter name of the pasture of the cow that arrives first back at the barn, the length of the path followed by that cow.

    Sample Input

    5
    A d 6
    B d 3
    C e 9
    d Z 8
    e Z 3

    Sample Output

    B 11

    Source

    样例输入

    5
    A d 6
    B d 3
    C e 9
    d Z 8
    e Z 3

    样例输出

    B 11

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部