Review the second figure and think of this problem, bare two-figure matching, the direct Hungarian algorithm can be, mark, this is a more useful dense map of the Hungarian algorithm template
Title: Topic link
AC Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cstring>#include<vector>#include<string>#include<queue>#include<map>#include<Set>#defineFrer () freopen ("In.txt", "R", stdin);#defineINF 0x3f3f3f3fusing namespacestd;Const intMAXN = -;intN, M, K;intG[MAXN][MAXN], NUM[MAXN];BOOLVIS[MAXN];BOOLFindint);intHungury ();intMain () {//Frer ()Ios::sync_with_stdio (0); Cin.tie (0); intu, v; while(Cin >> N &&N) {cin>> m >>K; Memset (g,0,sizeof(g)); while(k--) {cin>> u >>v; G[U][V]=1; } cout<< Hungury () <<Endl; } return 0;}BOOLFindintu) { for(intv =0; v < m; ++v) {if(G[u][v] &&!Vis[v]) {Vis[v]=true;//Mark this point has been tried and modified in this match if(Num[v] = =-1||find (Num[v])) {Num[v]=u; return true; } } } return false;}intHungury () {intAns =0; memset (num,-1,sizeof(num)); for(inti =0; I < n; ++i) {memset (Vis,false,sizeof(VIS)); if(Find (i)) + +ans; } returnans;}
Tracer Deployment UVALive-8271 binary map matching