Map minimum path coverage: from a certain point along the direction of the path, do not walk the loop, can be all the nodes traverse.
#include <iostream>#include<cstdio>#include<vector>#include<Set>using namespacestd;Const intmax_n= the;intMatch[max_n];BOOLVis[max_n];Set<int>Insert;vector<int>E[max_n];intn,k;voidInit () {scanf ("%d%d",&n,&k); memset (Match,-1,sizeof(match)); Insert.clear (); for(intI=0; i<max_n; i++) {e[i].clear (); } intA, B; for(intI=0; i<k; i++) {scanf ("%d%d", &a, &b); Insert.insert (a); E[a].push_back (b); }}BOOLDfs (intx) { for(intI=0; I<e[x].size (); i++) { intu=E[x][i]; if(!Vis[u]) {Vis[u]=1; if(match[u]==-1||Dfs (Match[u])) {Match[u]=x; return true; } } } return false;}intbi_matching () {intans=0; Set<int>:: Iterator it; for(It=insert.begin (); It!=insert.end (); it++) { intI= (*it); memset (Vis,false,sizeof(VIS)); if(Dfs (i)) ans++; } returnans;}intMain () {intT; scanf ("%d",&t); while(t--) {Init (); printf ("%d\n", N-bi_matching ());//minimum path overwrite = node number-minimum point set overwrite}return 0;}
HDOJ1151 Map Minimum Path overlay