Poj2594 (minimum path overwrite + floyd)

Source: Internet
Author: User

Poj2594 (minimum path overwrite + floyd)

 

Question:
In a directed graph, there are several connection routes. Ask how many robots can be placed at least to walk through the points on the entire graph. Minimum path coverage.

Analysis:
At this time, the minimum path overwrite problem occurs. The minimum path overwrite = | V |-Maximum number of matches. (For the minimum path coverage and maximum matching problem, I don't know the concept here.) Of course, there is still a problem !!If the edges of a directed graph have an intersection, we cannot simply perform binary matching on the source image.For more information, see

# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
Using namespace std; int n, m, sum, ans [505], v [505], map [505] [505]; void floyd () // calculate the closure of the graph {for (int k = 1; k <= n; k ++) {for (int I = 1; I <= n; I ++) {if (map [I] [k] = 1) {for (int j = 1; j <= n; j ++) {if (map [k] [j] = 1) map [I] [j] = 1 ;}}} int dfs (int x) // find the augmented path {for (int I = 1; I <= n; I ++) {if (map [x] [I] = 1 & v [I] = 0) {v [I] = 1; if (ans [I] = 0 | (ans [I]! = 0 & dfs (ans [I]) = 1) {ans [I] = x; return 1 ;}} return 0 ;}int main () {while (scanf (% d, & n, & m )! = EOF & (n | m) {memset (ans, 0, sizeof (ans); memset (map, 0, sizeof (map )); for (int I = 1; I <= m; I ++) {int x, y; scanf (% d, & x, & y ); map [x] [y] = 1;} floyd (); sum = 0; for (int I = 1; I <= n; I ++) // calculate the maximum match {memset (v, 0, sizeof (v); int t = dfs (I); if (t = 1) sum ++ ;} printf (% d, n-sum);} return 0 ;}
     
    
   
  

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.