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 ;}