[24 questions about network stream] minimum path coverage (Bipartite Graph Matching) programming questions, 24 bipartite

Source: Internet
Author: User

[24 questions about network stream] minimum path coverage (Bipartite Graph Matching) programming questions, 24 bipartite
Question

Principle: Minimum path overwrite = point-matching number;
It is easy to understand: the two points can be matched, which is equivalent to putting them in and querying the set, and querying the number of sets is the number of paths;
However, my understanding of graph creation is always incorrect;
I ran a Binary Graph dyeing and divided it into two sets and ran a Binary Graph Matching. The error was that I did not split the points;
So I think that each vertex can only go once, so each vertex is connected to a side with a capacity of 1. The error is that there is no connection between electricity and points,No adjustment function;
The correct method for creating a graph is as follows: each vertex is split into I + n but not connected; S is connected to I Capacity 1; I + n is connected to T capacity 1; if the two vertices are connected to x and are connected to y + n (this is a clever way of creating a graph), we can say that the two vertices haveInvisibleContact;
Take 1-> 2-> 3 as an example.

However, it is difficult for me to create a graph. nxt [] and pre [] record the successor and precursor of the vertex respectively, and recursive output; <喎?https: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxoMiBpZD0 = "code"> code

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
Using namespace std; const int maxn = 1000001; const int inf = 1e9; queue
     
      
Q; int n, m, k, maxflow, a [maxn], S, T; struct Edge {int next, to, dis;} edge [maxn <1]; int num_edge =-1, head [maxn], cur [maxn], deep [maxn]; int nxt [maxn], pre [maxn]; // which void add_edge (int from, int to, int dis) {edge [++ num_edge] is the first vertex and the last vertex of vertex I? next = head [from]; edge [num_edge]. dis = dis; edge [num_edge]. to = to; head [from] = num_edge;} void add (int x, int y, int z) {add_edge (x, y, z); add_edge (y, x, 0);} bool bfs (int s, int t) {mems Et (deep, 0x7f, sizeof (deep); for (int I = 0; I <= t; I ++) cur [I] = head [I]; while (! Q. empty () q. pop (); q. push (s); deep [s] = 0; while (! Q. empty () {int now = q. front (); q. pop (); for (int I = head [now]; I! =-1; I = edge [I]. next) {int to = edge [I]. to; if (deep [to]> inf & edge [I]. dis) {deep [to] = deep [now] + 1; q. push (to) ;}}return deep [t]
      
     
    
   
  
 
Summary

Output Method

<

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.