题目名称 315. [POJ 3255] 地砖RoadBlocks
输入输出 block.in/out
难度等级 ★★★
时间限制 1000 ms (1 s)
内存限制 128 MiB
测试数据 10
题目来源 GravatarBYVoid 于2009-04-14加入
开放分组 全部用户
提交状态
分类标签
USACO 图论 最短路 次短路
分享题解
通过:106, 提交:222, 通过率:47.75%
Gravatarszzy 100 0.000 s 10.04 MiB C++
GravatarAptal丶 100 0.004 s 10.03 MiB C++
GravatarAptal丶 100 0.004 s 10.03 MiB C++
Gravatarszzy 100 0.004 s 10.03 MiB C++
Gravatarszzy 100 0.004 s 10.04 MiB C++
Gravatarszzy 100 0.004 s 10.04 MiB C++
Gravatarszzy 100 0.005 s 10.03 MiB C++
Gravatarszzy 100 0.006 s 20.06 MiB C++
GravatarAptal丶 100 0.009 s 10.03 MiB C++
GravatarLCWhiStLe 100 0.010 s 0.26 MiB C++
关于 地砖RoadBlocks 的近10条评论(全部评论)
次短路留念
Gravatar健康铀
2024-01-25 21:46 3楼
排行榜上那两个人简直是丧心病狂!!!!!!!
GravatarLCWhiStLe
2017-08-24 08:21 2楼
次短路不解释
Gravatar乌龙猹
2014-10-25 08:03 1楼

315. [POJ 3255] 地砖RoadBlocks

★★★   输入文件:block.in   输出文件:block.out   简单对比
时间限制:1 s   内存限制:128 MiB

Description

Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old home too quickly, because she likes the scenery along the way. She has decided to take the second-shortest rather than the shortest path. She knows there must be some second-shortest path.

The countryside consists of R (1 ≤ R ≤ 100,000) bidirectional roads, each linking two of the N (1 ≤ N ≤ 5000) intersections, conveniently numbered 1..N. Bessie starts at intersection 1, and her friend (the destination) is at intersection N.

The second-shortest path may share roads with any of the shortest paths, and it may backtrack i.e., use the same road or intersection more than once. The second-shortest path is the shortest path whose length is longer than the shortest path(s) (i.e., if two or more shortest paths exist, the second-shortest path is the one whose length is longer than those but no longer than any other path).


贝茜搬到了一个小农场去住,但她很享受偶尔回去看看她的一个好朋友。贝茜很喜欢沿途的风景,因此她希望路上走的尽可能慢一些。于是她决定走次短路而不是最短路。

城郊包含R(1<=R<=100,000)条双向的路,它们分别连接了N(1<=N<=5000)个十字路口(节点),为了方便我们把它们标记为1..N。贝茜从1号节点出发,她的好朋友(目的地)在N号节点。

次短路和最短路可以部分重合,次短路也有可能经过同一条路或同一个节点多次。次短路是长于最短路的路中最短的那一条。当有多个最短路存在时,次短路是其他所有路中最短的那条。


Input

Line 1: Two space-separated integers: N and R

Lines 2..R+1: Each line contains three space-separated integers: A, B, and D that describe a road that connects intersections A and B and has length D (1 ≤ D ≤ 5000)


输入:

第1行:两个被空格分开的整数N和R

第2..R+1行:每行包括三个由空格分开的整数A,B和D组成。用来描述连接节点A和节点B之间路径的长度是D(1<=D<=5000)。


Output

Line 1: The length of the second shortest path between node 1 and node N


输出:

第一行:一个整数表示从节点1到节点N之间次短路的长度。


Sample Input

4 4
1 2 100
2 4 200
2 3 250
3 4 100

Sample Output

450

Hint

Two routes: 1 -> 2 -> 4 (length 100+200=300) and 1 -> 2 -> 3 -> 4 (length 100+250+100=450)


提示:

样例中由两条从节点1到节点N的路分别是1->2->4(len=100+200=300(最短路))和1->2->3->4(100+250+100=450(次短路))。

译byKZFFFFFFFF