POJ-2594 Treasure Exploration binary map matching + Floyd

Source: Internet
Author: User

The main idea: there are n mines on Mars, a bit of mine there is a road, because in Mars is more special, the road becomes a one-way road, and the robot can only appear in this road two endpoints, asked how many robots need to be sent, in order to explore these mines

Problem-solving ideas: The road can be spliced up to form a new road, so in the given conditions can also be extended, with Floyd will be all the points can be connected to find out
Next is the binary matching process, to find the maximum number of matches, in the N-Max match number is the answer

#include <cstdio>#include <cstring>#include <vector>using namespace STD;Const intN =510;intRoad[n][n], N, M;intLink[n], vis[n];voidFloyd () { for(intK =1; K <= N; k++) for(inti =1; I <= N; i++) for(intj =1; J <= N; J + +)if(Road[i][k] && road[k][j]) road[i][j] =1;}voidInit () {intx, y;memset(Road,0,sizeof(road)); for(inti =0; I < m; i++) {scanf("%d%d", &x, &y); Road[x][y] =1; }memset(Link,0,sizeof(link)); Floyd ();}BOOLDfsintu) { for(inti =1; I <= N; i++)if(Road[u][i] &&!vis[i]) {Vis[i] =1;if(!link[i] | | DFS (LINK[I)) {Link[i] = u;return true; }        }return false;}voidHungary () {intAns =0; for(inti =1; I <= N; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", N-ans);}intMain () { while(scanf("%d%d", &n, &m)! = EOF && n + m) {init ();    Hungary (); }return 0;}

POJ-2594 Treasure Exploration binary map matching + 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.