「POJ2404」Jogging Trails

2015年1月2日3,9380

Description

Gord is training for a marathon. Behind his house is a park with a large network of jogging trails connecting water stations. Gord wants to find the shortest jogging route that travels along every trail at least once.

Input

Input consists of several test cases. The first line of input for each case contains two positive integers: n <= 15, the number of water stations, and m < 1000, the number of trails. For each trail, there is one subsequent line of input containing three positive integers: the first two, between 1 and n, indicating the water stations at the end points of the trail; the third indicates the length of the trail, in cubits. There may be more than one trail between any two stations; each different trail is given only once in the input; each trail can be travelled in either direction. It is possible to reach any trail from any other trail by visiting a sequence of water stations connected by trails. Gord’s route may start at any water station, and must end at the same station. A single line containing 0 follows the last test case.

Output

For each case, there should be one line of output giving the length of Gord’s jogging route.

Sample Input

Sample Output

题解

带权无向图上的中国邮路问题

若原图不连通则无解。若所有点的度均为偶数,则存在欧拉回路,所有边权加和即为结果。

否则必有偶数个奇度点,将这些奇点拉出来构建新图,任意两点之间的边权为原图中两点之间的最短距离,对新图求一次一般图的最小权完美匹配,加上原图所有边权和即为最终结果。

本题最小权完美匹配用状压DP解决,或者带花树~ TAT 流算法是不正确的。

 

 

avatar
  Subscribe  
提醒