zoukankan      html  css  js  c++  java
  • poj3463 Sightseeing(读题很重要)

    译文:

    题目描述

    旅行社YPH(Your Personal Holiday)在Benelux城设置观光大巴啦。每天大巴都会从一个城市S到另一个城市F。这样旅客们就可以游览沿路的景点了。此外,总线在一些美丽的城市中设置了很多站点(零个或多个),旅客们可以从这些站点下车参观。

    不同的游客可能有不同的偏好,他们想看到的风景也可能不尽相同,但是路线的起点和终点一定要是S和F,因此YPH提供了一些不同的路线,游客们就能够从中进行选择了。由于酒店已经提前预定了,路线的起点和终点一定是固定的。两条路线中有一步不相同,就认为这两条路径不同。

    当然,游客的选择也是一个限制的。为了留下足够的时间来观光(实际上是为了省油),旅游大巴只选择S到F中较短的路线 .ta必须是距离最短,或是比最短路距离大一的路线。实际上,仅仅是允许比最短路长一单位的路线,就可以给旅客不少的选择。这就可以增加YPH的人气。

    这里写图片描述
    例如, 像上面这幅地图, 一共有两条路线从 S = 1 到 F = 5: 1 → 2 → 5 以及 1 → 3 → 5, 两条路线的长度都是6. 有一条长度为7的路线(比最短路距离大一): 1 → 3 → 4 → 5, of length 7.

    现在, 给出一个(有向)地图以及两个城市S 和 F, YPH的旅游策划想要知道符合上述限制的道路有几条。

    输入

    输入的第一行包含一个数字T,表示测试点的数量,每个测试点包含以下几部分:

    第一行包含两个整数N和M,用一个空格隔开,2 ≤ N ≤ 1,000 且1 ≤ M ≤ 10, 000: 分别表示城市数量和单向道路的数量

    接下来的M行,每行包含三个数字 A,B,L, 数字之间用一个空格隔开,1 ≤ A, B ≤ N, A ≠ B且1 ≤ L ≤ 1,000,描述一条从A到B的道路,长度为L

    道路是单向的,因此,如果有一条路从A到B,那么不一定B就可以到达A,有可能有多条不同的从A到B的道路。

    最后一红包含两个整数S,T,用一个空格隔开, 1 ≤ S, F ≤ N 且S ≠ F: 表示路线的起点和终点

    从S到F一定有一条路线

    输出

    对于输入的每一个测试点,单独输出一行,包含一个整数: 表示最短路和比最短路长一单位的路径的总数. 保证所有数字<=10^9 = 1,000,000,000.

    样例输入
    2
    5 8
    1 2 3
    1 3 2
    1 4 5
    2 3 1
    2 5 3
    3 4 2
    3 5 4
    4 5 3
    1 5
    5 6
    2 3 1
    3 2 1
    3 1 10
    4 5 2
    5 2 7
    5 2 7
    4 1

    样例输出
    3
    2

    原文:

    Description

    Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. On this way, the tourists in the bus can see the sights alongside the route travelled. Moreover, the bus makes a number of stops (zero or more) at some beautiful cities, where the tourists get out to see the local sights.

    Different groups of tourists may have different preferences for the sights they want to see, and thus for the route to be taken from S to F. Therefore, Your Personal Holiday wants to offer its clients a choice from many different routes. As hotels have been booked in advance, the starting city S and the final city F, though, are fixed. Two routes from S to F are considered different if there is at least one road from a city A to a city B which is part of one route, but not of the other route.

    There is a restriction on the routes that the tourists may choose from. To leave enough time for the sightseeing at the stops (and to avoid using too much fuel), the bus has to take a short route from S to F. It has to be either a route with minimal distance, or a route which is one distance unit longer than the minimal distance. Indeed, by allowing routes that are one distance unit longer, the tourists may have more choice than by restricting them to exactly the minimal routes. This enhances the impression of a personal holiday.

    这里写图片描述
    For example, for the above road map, there are two minimal routes from S = 1 to F = 5: 1 → 2 → 5 and 1 → 3 → 5, both of length 6. There is one route that is one distance unit longer: 1 → 3 → 4 → 5, of length 7.

    Now, given a (partial) road map of the Benelux and two cities S and F, tour operator Your Personal Holiday likes to know how many different routes it can offer to its clients, under the above restriction on the route length.

    Input

    The first line of the input file contains a single number: the number of test cases to follow. Each test case has the following format:

    One line with two integers N and M, separated by a single space, with 2 ≤ N ≤ 1,000 and 1 ≤ M ≤ 10, 000: the number of cities and the number of roads in the road map.

    M lines, each with three integers A, B and L, separated by single spaces, with 1 ≤ A, B ≤ N, A ≠ B and 1 ≤ L ≤ 1,000, describing a road from city A to city B with length L.

    The roads are unidirectional. Hence, if there is a road from A to B, then there is not necessarily also a road from B to A. There may be different roads from a city A to a city B.

    One line with two integers S and F, separated by a single space, with 1 ≤ S, F ≤ N and S ≠ F: the starting city and the final city of the route.

    There will be at least one route from S to F.

    Output

    For every test case in the input file, the output should contain a single number, on a single line: the number of routes of minimal length or one distance unit longer. Test cases are such, that this number is at most 10^9 = 1,000,000,000.

    Sample Input
    2
    5 8
    1 2 3
    1 3 2
    1 4 5
    2 3 1
    2 5 3
    3 4 2
    3 5 4
    4 5 3
    1 5
    5 6
    2 3 1
    3 2 1
    3 1 10
    4 5 2
    5 2 7
    5 2 7
    4 1

    Sample Output
    3
    2

  • 相关阅读:
    [Noip模拟题]教主的魔法
    [Usaco2005 Jan]Muddy Fields泥泞的牧场
    机器学习-数据可视化神器matplotlib学习之路(三)
    机器学习-数据可视化神器matplotlib学习之路(二)
    机器学习-数据可视化神器matplotlib学习之路(一)
    机器学习-ID3决策树算法(附matlab/octave代码)
    Hive安装-windows(转载)
    windows下hadoop安装配置(转载)
    C#发送邮件异常:根据验证过程,远程证书无效
    C#多线程--线程池(ThreadPool)
  • 原文地址:https://www.cnblogs.com/wutongtong3117/p/7673230.html
Copyright © 2011-2022 走看看