Related Topics: Http://codeforces.com/problemset/problem/618/D
The minimum path overlay (all points) of the graph can be solved by a binary graph, n-Max match.
The minimal path overlay (all points) of the non-graph seems to be a more difficult problem
So what's a good way to find the smallest path coverage for a special graph-tree?
First of all, we can consider using DP solution to maintain the minimum path coverage that can be obtained with each subtrees tree leaving an upward extensible path f[i][1], and the smallest path coverage f[i][0] that can be obtained without leaving an upward extensible path for each subtrees tree. Transfer here is not much to repeat, but one thing is obvious, for each point i,f[i][0]≥f[i][1]. And this point can give us a little new ideas, whether each point as far as possible to "do not leave the posterior", that is, can "turn down"? The answer is yes.
The first thing to be clear is to ask for the minimum path coverage, which is to make the path cover as many edges as possible .
We for each point, find it child "can extend" the number of tot, if tot=0, then this point can only become "extensible" point, if tot=1, then this only a son extends up to the side must join the answer U, at the same time the current point has become "extensible" point, If Tot≥2 then this point can be combined with any two sons to extend the edge of "for one", the two-side joins the answer U, so that the number of paths virtually minus 1, which also validates the correctness of greed, because if not merged, the answer will not be better at this time, Then the continuation of the extension of the result is the best-1, the early reduction of the same as the late, as early as the reduction, lest "over the village did not have this shop."
Finally DFS ends and gets the answer u, the answer u is actually up to how many edges to cover. So the smallest path is n-u.
voidDfs (intXintFA) { inted =last[x], Dr; inttot =0; while(Ed! =-1) {Dr=other[ed]; if(Dr! =FA) {Dfs (dr, X); if(Flag[dr]) tot++; } Ed=pre[ed]; } if(Tot = =0) Flag[x] =true; Else if(Tot = =1) cnt++, flag[x] =true; ElseCNT + = 2LL, flag[x] =false;}
View Code
Find the smallest path cover of a tree