posts - 74,  comments - 33,  trackbacks - 0
Farm Tour
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1152 Accepted: 351

Description

When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000) fields numbered 1..N, the first of which contains his house and the Nth of which contains the big barn. A total M (1 <= M <= 10000) paths that connect the fields in various ways. Each path connects two different fields and has a nonzero length smaller than 35,000.

To show off his farm in the best way, he walks a tour that starts at his house, potentially travels through some fields, and ends at the barn. Later, he returns (potentially through some fields) back to his house again.

He wants his tour to be as short as possible, however he doesn't want to walk on any given path more than once. Calculate the shortest tour possible. FJ is sure that some tour exists for any given farm.

Input

* Line 1: Two space-separated integers: N and M.

* Lines 2..M+1: Three space-separated integers that define a path: The starting field, the end field, and the path's length.

Output

A single line containing the length of the shortest tour.

Sample Input

4 5
1 2 1
2 3 1
3 4 1
1 3 2
2 4 2

Sample Output

6

Source

USACO 2003 February Green
本题题意大概是最小费用流!
在处理的时候要处理重边。。。。。其实我们可以证明的,就是如果存在重边我们最多只需要记录两个边就可以解题!
以最大流最小费用流原理我们知道,消负权最后达到的效果就是最大流的情况下不存在流经两次的边。。。。。即每条边最多只能流经一次,由此可知我们可以最多储存两条重边!
AC 了 79ms很慢
posted on 2009-03-17 19:40 KNIGHT 阅读(214) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2009年3月>
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(8)

随笔档案

文章档案

Friends

OJ

搜索

  •  

最新评论

阅读排行榜

评论排行榜