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