Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA了十几次,终于AC了,知道用bellman-ford时候哪里错了

Posted by lzs12348 at 2012-07-12 14:33:54 on Problem 1860
参考了http://poj.org/showmessage?message_id=158581,非常感谢!

WA了十几次,终于知道用bellman-ford时候哪里错了,在更新时候,一定要先判断d[j] > 0(j是图中一个点),否则就会WA。也就每次更新要从钱是正数的点开始,如果不这样就会导致中间的值算错,最后导致结果错误,而且题目上也是这么要求的。

还有关于循环次数,n-1次足够了,只要找出环就行了,不是要用5n次,连d[s] > v都不用判断。至于为什么最多需要n-1次,是因为从s到另一点的任何路径最多包含n-1条边,每一次循环至少会更新一条边,所以n-1次循环后所有路径一定都被更新完成。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator