A minimal path overlay to a acyclic graph (DAG)

Source: Internet
Author: User

Minimum path overrides for Dags

definition : In a graph, find the fewest paths so that the paths pass through all the points.

The minimum path overlay is divided into the minimum disjoint path overlay and the smallest disjoint path overlay .

minimum disjoint path overrides : Each path passes through a different vertex. With a minimum path overlay of 3. That is 1->3>4,2,5.

minimum disjoint path overlay : Each path passes the same vertex. If it has a minimum path, the number of overrides is 2. That is 1->3->4,2->3>5.

In particular, each point itself can also be called a path overlay, except that the length of the path is 0.

Minimum disjoint path overlay for Dag

algorithm : The original image of each point V split into $ $V _x$$ and $ $V _y$$ two points, if there is a forward edge a->b, then add Edge $ $A _x->b_y$$. This gives you a two-part picture. So the minimum path overlay = The number of nodes in the original image-the maximum match for the new graph.

proof : At first each point is independent of a path, with a total of n disjoint paths. Each time we find a matching edge in a binary graph, it is equivalent to combining two paths into one path, which is equivalent to reducing the number of paths by 1. So a few matching edges are found, and the number of paths is reduced. So there is a minimum path overlay = The original number of nodes-the maximum match for the new graph.

Because there is no common point between the paths, there is no common point between the added edges, which is the definition of the match.

Exercise : POJ1422

////main.cpp//POJ1422 minimum do not want to cross path overlay////Created by Bemaster on 16/4/8.//copyright©2016 year Bemaster. All rights reserved.//#include<iostream>#include<stdio.h>#include<string.h>#include<vector>using namespacestd;Const intN = $+Ten; Vector<int>G[n];intCy[n];BOOLVis[n];BOOLDfsintu) {     for(intI=0; I<g[u].size (); ++i) {        intv =G[u][i]; if(Vis[v])Continue; VIS[V]=true; if(cy[v]==-1||DFS (Cy[v])) {Cy[v]=u; return true; }    }    return false;}intSolveintN) {    intRET =0; memset (CY,-1,sizeof(CY));  for(intI=1; i<=n;++i) {memset (Vis,0,sizeof(VIS)); RET+=DFS (i); }    returnN-ret;}intMainintargcConst Char*argv[]) {    intt,n,m; intu,v; scanf ("%d",&t);  while(t--) {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;++i) g[i].clear ();  for(intI=0; i<m;++i) {scanf ("%d%d",&u,&v);        G[u].push_back (v); }                intAns =solve (n); printf ("%d\n", ans); }    return 0;}

Minimum disjoint path overlay for Dag

algorithm : First use Floyd to find the original image of the transitive closure, that is, if a to B has a path, then add Edge a->b. It then translates to the minimal disjoint path coverage problem.

proof : In order to connect two points, a path may pass through the intermediate points of other paths. Like 1->3->4,2->4->5. But if two points A and B are connected, but in the middle need to pass through other points, then the two points can be added to the edge, then a can be directly to the B, do not have to pass through the midpoint, then converted to the smallest disjoint path coverage.

title : POJ2594

////main.cpp//POJ2594 minimum disjoint path overlay////Created by Bemaster on 16/4/8.//copyright©2016 year Bemaster. All rights reserved.//#include<iostream>#include<stdio.h>#include<string.h>#include<vector>using namespacestd;Const intN = -+Ten;BOOLDis[n][n];BOOLVis[n];intCy[n];voidFloydintN) {     for(intI=1; i<=n;++i) for(intj=1; j<=n;++j) for(intk=1; k<=n;++k)if(Dis[i][k] && dis[k][j])//transitive accessibilityDIS[I][J] =true;}BOOLDfsintUintN) {     for(intI=1; i<=n;++i) {        if(!vis[i] &&Dis[u][i]) {Vis[i]=true; if(cy[i]==-1||DFS (Cy[i], N)) {Cy[i]=u; return true; }        }    }    return false;}intSolveintN) {    intCNT =0; memset (CY,-1,sizeof(CY));  for(intI=1; i<=n;++i) {memset (Vis,0,sizeof(VIS)); CNT+=DFS (i, n); }    returnN-CNT;}intMainintargcConst Char*argv[]) {    intn,m; intb;  while(SCANF ("%d%d", &n,&m), n+m) {         for(intI=1; i<=n;++i) for(intj=1; j<=n;++j) Dis[i][j]=false;  for(intI=1; i<=m;++i) {scanf ("%d%d",&a,&C); DIS[A][B]=true;        } Floyd (n); intAns =solve (n); printf ("%d\n", ans); }    return 0;} 

Reference :

Two-part picture lecture hall--complete deal with maximum number of matches (minimum number of covers), maximum independent number, minimum path coverage, weighted optimal matching

A minimal path overlay to a acyclic graph (DAG)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.