Title Description
«Problem Description:
Given the graph g= (v,e). Set P is a simple way for g (vertices do not intersect) collection. If each vertex in V happens to be on one of the lines of P, then p is a path overlay of G. The path in P can start at any vertex of V, and the length is arbitrary, specifically, it can be 0. The minimum path coverage for G is the path coverage with the least number of path bars in G. An effective algorithm is designed to find the minimum path coverage of a direction-free graph G. Tip: Set v={1,2, ..., n}, construct network g1= (V1,E1) as follows:
Each edge has a capacity of 1. The maximum flow of the network G1 (0 x, 0 y).
«Programming Tasks:
For a given given direction-free graph G, programming to find a minimum path overlay of G.
Input/output format
Input Format:
The 1th line of the piece has 2 positive integers n and M. n is the number of vertices of the given direction-free graph G, and M is the number of sides of G. The next M-line has 2 positive integers i and j for each row, indicating a forward edge (I,J).
output Format:
Starting with line 1th, each line outputs a path. The last line of the file is the minimum number of paths.
Input/Output sample
Input Sample # #:
One A1 21 31 42 53 64 75 86 97 Ten8 One9 OneTen One
Sample # # of output:
1 4 7 Ten One 2 5 8 3 6 9 3
Solution
1. Model: The smallest path overlay to a acyclic graph dag
- S->xi, with a capacity of 1.
- Xi->yj, (i, J) ∈e, upper capacity is 1.
- Yi->t, the upper bound of capacity is 1.
Minimum path overlay for Dag =| v|-corresponds to the maximum matching of the binary graphs.
What is a constraint? There is a critical point in the definition of a path: the allowable length is 0. The existence of the solution has been ensured. Therefore, just satisfy: for any point, there is at most one edge associated with it and the out edge associated with it is selected.
The matching of the binary graphs can be viewed from the point of view of the vertices, or from the perspective of the edges: select some edges so that each vertex is associated with at most one edge. Compared with the constraint of this problem, it is found that the direction-free graph is not a binary graph, and for vertices, the edge is divided into two categories: the Edge and the out edge. Consider splitting the point I into XI, Yi, into the edge to Yi, out of the side from XI. In this way, the constraint of the problem is consistent with that of the binary graph.
What is the goal? Minimizes the number of path overrides. In addition to the direct number, what can be used to describe the number of path coverage? The number of heads or the number of tails. What kind of point is the head? There is no matching edge associated with the corresponding Yi. Tail? There is no matching edge associated with the corresponding XI. Therefore, the minimum path of the Dag overrides the =| v|-corresponds to the maximum matching of the binary graphs.
Hzwer Here's another more concise way to look at it:
If there is no match, it is obvious that the N path can cover all points, and the two point matching means that they can be overwritten with one path and the number of paths can be reduced by 1.
I also have a way of looking at the alternative:
The network stream with the upper bound.
Step 1
-S->XI, upper capacity is 1.
-Xi->yi, the lower bound of capacity is 1, upper bound INF.
-Yi->xj, (i, J) ∈e, upper capacity is 1.
-Yi->t, upper capacity is 1.
solves the s-t minimum flow.
Step 2
See a feasible flow, and omit the usual steps to solve the s-t feasible flow.
The network transformation is:
-Xi->s, upper capacity is 1.
-Yi->xj, (i, J) ∈e, upper capacity is 1.
-T->yi, upper capacity is 1.
The T-S maximum flow of this network is superimposed with the feasible flow of the original s-t, which is the original s-t minimum flow. S-t the value of the feasible stream is | v|, with | v| to reduce t-s maximum flow.
This method of view is essentially the same as hzwer, but it is obtained from the formal transformation.
Why are Dags emphasized? Because we simply split, match, and don't care whether these two points are already in the same path. For example, a ring, the maximum match of the corresponding binary graph is | v|, in fact, as a "path" of the beginning and finish, it can not be sealed.
Reprinted from Http://blog.csdn.net/ruoruo_cheng
Therefore, the ans=n-maximum match
2. Algorithms
Realization of maximal matching of binary graph with maximum flow of network flow
[Network Flow Training 3] [Minimum path coverage problem]