博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3463 Sightseeing(读题很重要)
阅读量:5154 次
发布时间:2019-06-13

本文共 4224 字,大约阅读时间需要 14 分钟。

译文:

题目描述

旅行社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

转载于:https://www.cnblogs.com/wutongtong3117/p/7673229.html

你可能感兴趣的文章
GIS坐标方面术语
查看>>
ANDROID内存优化(大汇总——中)
查看>>
3.3 idea中使用git遇到的一些问题
查看>>
windows应用程序配置log4net日志记录
查看>>
Unity3D For Android 开发教程【转http://game.ceeger.com/Unity/Doc/2011/Unity3D_For_Android.html】...
查看>>
Map集合HashMap,TreeMap
查看>>
用 1,2,2,3,4,5 六个数字,打印出所有不同的排列,要求:"4"不能在第三位,"3"与"5"不能相连...
查看>>
10道典型的JavaScript面试题
查看>>
c# 对象类型、对象总结 ref、out关键字
查看>>
python random模块
查看>>
javascript 和php的要点概括
查看>>
国际聚餐--DDM组圣诞party
查看>>
操作系统
查看>>
20150715竞赛总结
查看>>
ASP.NET中检测图片真实否防范病毒上传
查看>>
Python
查看>>
[ 转载 ] Java基础11--Java总结篇系列:Java泛型
查看>>
40086311Nim
查看>>
CSS实现背景图片屏幕自适应
查看>>
JS强制刷新页面、清除缓存刷新
查看>>