这个类比最小覆盖去做匹配,对一个点,他一定只在一个环上,那么他必定只有一个入度,一个出度,这样就可以把出度和入度两两匹配,然后找匹配价值的最小值就好了。。
然后一个坑了窝不久的是自己的km板子是得建完全图才能跑得懂的,所以对于一些无用边也得给个inf的权值加进图中。。
而判断能不能用有向环覆盖的条件是没有用到那些inf的边,即最终答案要小于inf。。
Tour
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 4224 Accepted Submission(s): 2010
Problem Description
In the kingdom of Henryy, there are N (2 <= N <= 200) cities, with M (M <= 30000) one-way roads connecting them. You are lucky enough to have a chance to have a tour in the kingdom. The route should be designed as: The route should contain one or more loops. (A loop is a route like: A->B->……->P->A.)
Every city should be just in one route.
A loop should have at least two cities. In one route, each city should be visited just once. (The only exception is that the first and the last city should be the same and this city is visited twice.)
The total distance the N roads you have chosen should be minimized.
Input
An integer T in the first line indicates the number of the test cases.
In each test case, the first line contains two integers N and M, indicating the number of the cities and the one-way roads. Then M lines followed, each line has three integers U, V and W (0 < W <= 10000), indicating that there is a road from U to V, with the distance of W.
It is guaranteed that at least one valid arrangement of the tour is existed.
A blank line is followed after each test case.
Output
For each test case, output a line with exactly one integer, which is the minimum total distance.
Sample Input
Sample Output
Source
2010 ACM-ICPC Multi-University Training Contest(6)——Host by BIT
Recommend
zhouzeyong | We have carefully selected several similar problems for you: 1533 3435 3395 3491 3657
Statistic | Submit | Discuss | Note