Original title Address
Can only say that the Hungarian algorithm can not be more cock, and the hint of the pseudo code can not be more cock!
Only use the second optimization, because the input point set to split into a, b seems to be very troublesome, simply do not use this optimization.
Code:
1#include <iostream>2#include <cstring>3 4 using namespacestd;5 6 #defineMax_vertex 10247 8 intN, M;9 Ten BOOLG[max_vertex][max_vertex]; One intM[max_vertex];//Match[vi] = UI indicates that the node matching the VI node is the UI A BOOLC[max_vertex];//Cover[vi] = True or false indicates whether the VI node has been queried - - BOOLFindpath (intu) { the for(inti =1; I <= N; i++) { - if(!g[u][i] | |C[i]) - Continue; -C[i] =true; + if(!m[i] | |Findpath (M[i])) { -M[u] =i; +M[i] =u; A return true; at } - } - return false; - } - - intsolve () { in intres =0; - to for(inti =1; I <= N; i++) { +Memset (c,0,sizeof(c)); - if(!m[i] &&Findpath (i)) theres++; * } $ Panax Notoginseng returnRes; - } the + intMain () { AMemset (G,0,sizeof(g)); theMemset (M,0,sizeof(m)); +scanf"%d%d", &n, &M); - for(inti =0; i < M; i++) { $ intu, v; $scanf"%d%d", &u, &v); -G[U][V] = G[v][u] =true; - } theprintf"%d\n", Solve ()); - return 0;Wuyi}
hihocoder#1121 two-part map determination