Graph Theory - cover and independent set of DAG

[Overview]

In a separate set of issues covered and the DAG, the common problems fall into three categories:

  • Minimum Vertex Cover path
  • The minimum point may be repeated to cover a path
  • The maximum number of independent set

These three types of problems can take advantage of Hungary bipartite graph algorithm to solve.

[] Covers the minimum path

Minimum path covered : Given a directed acyclic graph, requires as few disjoint simple path, covering all vertices directed acyclic graph (each vertex is covered exactly once)

The promotion Koning theorem: DAG = DAG top cover minimum path count - largest number of matched new bipartite graph

For new bipartite graph is a DAG FIG original G = (V, E), n = | V | come split point:

  • Each of the G point number x is split into two points x and x + n is
  • 1 ~ n points of the left portion bipartite graph, n + 1 ~ 2n points as a right portion of FIG bipartite
  • For each directed edge of the original (x, y), the point x between the left portion and the right portion of FIG point y + n bipartite side connected
  • Resulting bipartite graph G is referred to as a split point bipartite graph  Gz

Simply put, the DAG of n and m are given points to construct a side of the n point adjacency matrix, the adjacency matrix, a bipartite graph is a new

int n,m;
bool vis[N];
int link[N];
bool G[N][N];
bool dfs(int x){
    for(int y=1;y<=m;y++){
        if(G[x][y]&&!vis[y]){
            vis[y]=true;
            if(link[y]==-1 || dfs(link[y])){
                link[y]=x;
                return true;
            }
        }
    }
    return false;
}
int hungarian(){
    int ans=0;
    for(int i=1;i<=n;i++){
        memset(vis,false,sizeof(vis));
        if(dfs(i))
            ans++;
    }
    return ans;
}
int main(){
    while(scanf("%d%d",&n,&m)!=EOF&&(n+m)){
        memset(link,-1,sizeof(link));
        memset(G,true,sizeof(G));
 
        while(m--){
            int x,y;
            scanf("%d%d",&x,&y);
            G[x][y]=false;
        }
 
        int mate=hungarian();//最大匹配数
        int res=n-mate;//最小路径点覆盖
 
        printf("%d\n",res);
    }
    return 0;
}

[Repeated minimum path point coverage / maximum independent set]

The maximum independent sets of : selecting a point set up, so that no connection to any two points are concentrated

The minimum point may be repeated to cover the path : Given a directed acyclic graph, requires as few can intersect simple path, covering all vertices directed acyclic graph (a vertex may be covered several times)

Minimum repeat Vertex Cover path may, if two paths: ... -> u -> p -> v -> ... and ... -> x -> p -> y -> ... intersect at point p, then add an edge (x, y) in the original image, so that the second path directly down x-> y, the point p can avoid duplication.

Further, if all the original points of indirect communication x, y directly connected to the upper side (x, y), then the minimum point of the path covered can be repeated , can be converted to a certain minimum path cover

Thus, for a directed acyclic graph G smallest path may cover overlapping points, equivalent to a DAG seek the Transitive Closure new view of the obtained G ', and then the G' minimum requirements on the path coverage point

DAG and seeking the maximum independent set, and find the minimum path cover the same idea may be repeated points.

​int n,m;
bool vis[N];
int link[N];
bool G[N][N];
bool dfs(int x){
    for(int y=1;y<=n;y++){
        if(G[x][y]&&!vis[y]){
            vis[y]=true;
            if(link[y]==-1 || dfs(link[y])){
                link[y]=x;
                return true;
            }
        }
    }
    return false;
}
int hungarian(){
    int ans=0;
    for(int i=1;i<=n;i++){
        memset(vis,false,sizeof(vis));
        if(dfs(i))
            ans++;
    }
    return ans;
}
void floyd(){//传递闭包
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                G[i][j]|=G[i][k]&G[k][j];
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        memset(link,-1,sizeof(link));
        memset(G,false,sizeof(G));
 
        scanf("%d%d",&n,&m);
        while(m--){
            int x,y;
            scanf("%d%d",&x,&y);
            G[x][y]=true;
        }
        floyd();//计算传递闭包

        int mate=hungarian();//最大匹配数
        int res=n-mate;//最大独立集、最小路径可重复点覆盖
 
        printf("%d\n",res);
    }
    return 0;
}

【example】

  • Dolls (HDU-4160) (minimum path coverage) : Click here
  • Robots (POJ-1548) (minimum path coverage) : Click here
  • Raid AIR (POJ-1422) (minimum path coverage) : Click here
  • Scheme Cab Taxi (POJ-2060 is) (minimum Manhattan distance path coverage +) : Click here
  • Company Repairing (POJ-3216) (+ Floyd minimum path coverage for the most short-circuit) : Click here
  • The Present II and Potter harry (HDU-3991) (+ Floyd minimum path coverage for the most short-circuit) : Click here
  • The Set the Maximum Unreachable the Node at The (UVALive-8456) (maximum independent set) : Click here
Released 1871 original articles · won praise 702 · Views 1.94 million +

Guess you like

Origin blog.csdn.net/u011815404/article/details/102649987