HUD-1142
来源:互联网 发布:伺服电机怎么编程控制 编辑:程序博客网 时间:2024/04/30 13:04
A Walk Through the Forest
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4843 Accepted Submission(s): 1759
Problem Description
Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he likes to walk home. To make things even nicer, his office is on one side of a forest, and his house is on the other. A nice walk through the forest, seeing the birds and chipmunks is quite enjoyable.
The forest is beautiful, and Jimmy wants to take a different route everyday. He also wants to get home before dark, so he always takes a path to make progress towards his house. He considers taking a path from A to B to be progress if there exists a route from B to his home that is shorter than any possible route from A. Calculate how many different routes through the forest Jimmy might take.
The forest is beautiful, and Jimmy wants to take a different route everyday. He also wants to get home before dark, so he always takes a path to make progress towards his house. He considers taking a path from A to B to be progress if there exists a route from B to his home that is shorter than any possible route from A. Calculate how many different routes through the forest Jimmy might take.
Input
Input contains several test cases followed by a line containing 0. Jimmy has numbered each intersection or joining of paths starting with 1. His office is numbered 1, and his house is numbered 2. The first line of each test case gives the number of intersections N, 1 < N ≤ 1000, and the number of paths M. The following M lines each contain a pair of intersections a b and an integer distance 1 ≤ d ≤ 1000000 indicating a path of length d between intersection a and a different intersection b. Jimmy may walk a path any direction he chooses. There is at most one path between any pair of intersections.
Output
For each test case, output a single integer indicating the number of different routes through the forest. You may assume that this number does not exceed 2147483647
Sample Input
5 61 3 21 4 23 4 31 5 124 2 345 2 247 81 3 11 4 13 7 17 4 17 5 16 7 15 2 16 2 10
Sample Output
24
Source
University of Waterloo Local Contest 2005.09.24
Recommend
Eddy | We have carefully selected several similar problems for you: 1217 1385 1162 1548 2544
- HUD-1142
- HUD
- HUD 1000
- HUD 1033
- HUD 4038
- HUD P1561
- HUD 4473
- HUD 4502
- Hud 4608
- hud 2073
- hud 1518
- Unity HUD
- UDK HUD
- hud 2795
- hud 4288
- hud Fibonacci
- hud 4790
- hud 3713
- Linux的gdb和Unix的dbx调试工具
- Oracle 10g 中处理Clob大字段
- C 语言输入年和月打印出本月的日历
- P2P原理 和技术演变(概念性质)
- 非格式化输入输出函数
- HUD-1142
- 第5天-4 rman】【rman 备份】【rman 还原】
- ORA-28001: the password has expired
- 黑马程序员-泛型的理解
- 第5天-5
- ACM 进阶学习第一课----同余相关之中国剩余定理
- atoi,atol,strtod,strtol,strtoul实现类型转换
- 第5天-5
- 从INT 到STRING的几种方法