21454_CowMarathon

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

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

Pro.ID

21454

Title

Cow Marathon

Title链接

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

AC

17

Submit

54

Ratio

31.48%

时间&空间限制

  • Time Limit: 200/100 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)
  • 描述

    After hearing about the epidemic of obesity in the USA, Farmer John wants his cows to get more exercise, so he has committed to create a bovine marathon for his cows to run. The marathon route will include a pair of farms and a path comprised of a sequence of roads between them. Since FJ wants the cows to get as much exercise as possible he wants to find the two farms on his map that are the farthest apart from each other (distance being measured in terms of total length of road on the path between the two farms). Help him determine the distances between this farthest pair of farms.

    输入

    * Line 1:   Two space-separated integers: N and M     2 ≤ N ≤ 40000,   1 ≤ M < 40,000

    * Lines 2..M+1:   Each line contains four space-separated entities, F1, F2, L, and D that describe a road. F1 and F2 are numbers of two farms connected by a road, L is its length, and D is a character that is either 'N', 'E', 'S', or 'W' giving the direction of the road from F1 to F2.

    * Line M+2:   A single integer, K (1 ≤ K ≤ 10,000), the number of FB's queries

    * Lines M+3..M+K+2:   Each line corresponds to a query from Farmer Bob and contains three space-separated integers: F1, F2, and I. F1 and F2 are numbers of the two farms in the query and I is the index (1 ≤ IM) in the data after which Bob asks the query. Data index 1 is on line 2 of the input data, and so on.

    输出

    Description

    After hearing about the epidemic of obesity in the USA, Farmer John wants his cows to get more exercise, so he has committed to create a bovine marathon for his cows to run. The marathon route will include a pair of farms and a path comprised of a sequence of roads between them. Since FJ wants the cows to get as much exercise as possible he wants to find the two farms on his map that are the farthest apart from each other (distance being measured in terms of total length of road on the path between the two farms). Help him determine the distances between this farthest pair of farms.

    Input

    * Line 1:   Two space-separated integers: N and M     2 ≤ N ≤ 40000,   1 ≤ M < 40,000

    * Lines 2..M+1:   Each line contains four space-separated entities, F1, F2, L, and D that describe a road. F1 and F2 are numbers of two farms connected by a road, L is its length, and D is a character that is either 'N', 'E', 'S', or 'W' giving the direction of the road from F1 to F2.

    * Line M+2:   A single integer, K (1 ≤ K ≤ 10,000), the number of FB's queries

    * Lines M+3..M+K+2:   Each line corresponds to a query from Farmer Bob and contains three space-separated integers: F1, F2, and I. F1 and F2 are numbers of the two farms in the query and I is the index (1 ≤ IM) in the data after which Bob asks the query. Data index 1 is on line 2 of the input data, and so on.

    Output

    Line 1:   An integer giving the distance between the farthest pair of farms.

    Sample Input

    7 6
    1 6 13 E
    6 3 9 E
    3 5 7 S
    4 1 3 N
    2 4 20 W
    4 7 2 S

    Sample Output

    52

    Hint

    The longest marathon runs from farm 2 via roads 4, 1, 6 and 3 to farm 5 and is of length 20+3+13+9+7=52.

    Source

    样例输入

    7 6
    1 6 13 E
    6 3 9 E
    3 5 7 S
    4 1 3 N
    2 4 20 W
    4 7 2 S

    样例输出

    52

    提示

    The longest marathon runs from farm 2 via roads 4, 1, 6 and 3 to farm 5 and is of length 20+3+13+9+7=52.


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部