Topic Portal
1 /*2 Test Instructions: Each time a row or column of obstacles can be eliminated, the minimum number of times required. 3 Hungarian algorithm: The row and column as two sets, when there are obstacles connected with an edge, the problem is converted to the minimum number of coverage = = Binary Graph maximum match4 Introduction to Fun:http://blog.csdn.net/dark_scope/article/details/88805475 */6#include <cstdio>7#include <algorithm>8#include <cstring>9#include <vector>Ten using namespacestd; One A Const intMAXN = 5e2 +Ten; - Const intINF =0x3f3f3f3f; -vector<int>G[MAXN]; the BOOLVIS[MAXN]; - intLK[MAXN]; - - BOOLDFS (intu) + { - for(intI=0; I<g[u].size (); ++i) + { A intv =G[u][i]; at if(!Vis[v]) - { -VIS[V] =true; - if(Lk[v] = =-1||DFS (Lk[v])) - { -LK[V] = u;return true; in } - } to } + return false; - } the * intHungaryintN) $ {Panax Notoginseng intres =0; memset (LK,-1,sizeof(LK)); - for(intI=1; i<=n; ++i) the { +memset (Vis,false,sizeof(Vis)); A if(DFS (i)) res++; the } + - returnRes; $ } $ - intMainvoid)//POJ 3041 Asteroids - { the //freopen ("poj_3041.in", "R", stdin); - Wuyi intN, K; the while(SCANF ("%d%d", &n, &k) = =2) - { Wu for(intI=1; i<=n; ++i) g[i].clear (); - for(intI=1; i<=k; ++i) About { $ intx, y; scanf ("%d%d", &x, &y); - g[x].push_back (y); - } - Aprintf ("%d\n", Hungary (n)); + } the - return 0; $}
Binary graph matching (Hungarian algorithm) POJ 3041 asteroids