POJ2594 Treasure Exploration "dichotomy Minimum path overlay" "Floyd"

Source: Internet
Author: User

Topic Links:

http://poj.org/problem?id=2594


Main topic:

Give you n locations, M-Bar has a forward edge, the known composition of the graph is a direction-free graph. Now we're going to put the robot through M in the place.

Edge to traverse N locations, Q: At least how many robots are required to traverse n locations.


Ideas:

This is a topic that asks for the minimum path coverage. and the general minimum path covered by the topic is not the same place is: Here the point can be

To repeat the traversal. This means that there can be two or more robots passing the same point. So, first create a binary map,

Both sides are n locations. Then, on the basis of the original image, we use the Floyd to find a transitive closure, that is, if point I can reach

Point J, and Point J can reach the point K, then can be as point I can skip the point J directly and reach the point K, you can create a directed

side (i,k). After the map is built, it is the general problem of the minimum path coverage of the binary graph. and the least path overlay of the binary diagram =

Points-Two The maximum match, with the Hungarian algorithm to find out the maximum matching of two graph can be.


AC Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace    std;const int maxn = 550;bool map[maxn][maxn],mask[maxn];int nx,ny;int cx[maxn],cy[maxn];void Floyd (int N)//Request delivery Closure {  for (int k = 1, k <= N; ++k) {for (int i = 1; I <= n; ++i) {for (int j = 1; j <= N;            ++J) {if (i! = J && Map[i][k] && map[k][j]) map[i][j] = 1; }}}}int Findpath (int u) {for (int i = 1; I <= NY; ++i) {if (Map[u][i] &&!            Mask[i]) {mask[i] = 1; if (cy[i] = =-1 | |                Findpath (Cy[i])) {Cy[i] = u;                Cx[u] = i;            return 1; }}} return 0;}    int Maxmatch ()//two divide maximum match {for (int i = 1; I <= NX; ++i) cx[i] = 1;    for (int i = 1; I <= NY; ++i) cy[i] = 1;    int res = 0;  for (int i = 1; I <= NX; ++i)  {if (cx[i] = = 1) {for (int j = 1; j <= NY; ++j) mask[j] = 0;        Res + = Findpath (i); }} return res;}    int main () {int n,m,u,v; while (~SCANF ("%d%d", &n,&m) && (n| |        M)) {memset (map,0,sizeof (MAP));            for (int i = 1; I <= M; ++i) {scanf ("%d%d", &u,&v);        MAP[U][V] = 1;        } Floyd (N);        NX = NY = N;    printf ("%d\n", N-maxmatch ()); } return 0;}


POJ2594 Treasure Exploration "dichotomy Minimum path overlay" "Floyd"

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.