bzoj#P1971. [POI2003] Connections
[POI2003] Connections
题目描述
Byteotian 基础服务政府准备研发一个计算机程序来帮助他们快速的找出两个城镇之间不同的路径。如果居民总是想找出最短的路径的话还是不难的。但是不幸的是,他们有时候想知道第 短的路径。而且除此之外,路径中自环、重复经过点是允许的。如果两个城镇之间有 条路径,他们的长度分别是 ,那么最短路径的长度为 ,次长为 ,第三长为 ,第四长的长度为 。
输入格式
In the first line of the standard input there are two positive integers and , separated by a single space. They are the number of towns in Byteotia and the number of roads connecting the towns, respectively. The towns are numbered from to .
In each of successive lines there are three integers separated by single spaces: and , . Each triple describes one one-way road of length enabling to move from the town to . For each two towns there exist at most one road that enables to move in the given direction.
In the following line there is one integer , denoting the number of queries. In the successive lines there are queries written, one per line. Each query has a form of three integers separated by single spaces: and . Such a query refers to the length of the -th shortest route from the town to the town .
输入文件的第一行有两个数 ,他们分别代表城镇总数和连接他们的道路总数。城镇编号从 到 。
接下来 行,每行 个整数: 和 ,它们代表一条长度为 有向边从 到 。不会有两条边有着相同的起点和终点。
接下来一行是一个整数 ,代表一共有 个询问。接下来 行每行三个数: 和 ,表示询问城镇 到城镇 的第 短路。
输出格式
对于每个询问,输出一行表示询问路径的长度,如果答案不存在,输出 -1
.
5 5
1 2 3
2 3 2
3 2 1
1 3 10
1 4 1
8
1 3 1
1 3 2
1 3 3
1 4 2
2 5 1
2 2 1
2 2 2
1 1 2
5
8
10
-1
-1
3
6
-1
数据规模与约定
对于 的数据,,,,,。