Hungarian algorithm templates
1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <vector>8 using namespacestd;9 Const intmxn=1010;Ten intRead () { One intx=0, f=1;CharCh=GetChar (); A while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx*F; the } - intMP[MXN][MXN]; - intN,m,et; - intLINK[MXN]; + BOOLVIS[MXN]; - BOOLDasointu) { + for(intI=1; i<=n;i++){ A if(!vis[i] &&Mp[u][i]) { atvis[i]=1; - if(link[i]==-1||DFS (Link[i])) { -link[i]=u; - return 1; - } - } in } - return 0; to } + intsolve () { - intres=0; the for(intI=1; i<=n;i++){ *memset (Vis,0,sizeofvis); $ if(DFS (i)) res++;Panax Notoginseng } - returnRes; the } + intMain () { AN=read (); M=read (); et=read (); the inti,j; + intu,v; - for(i=1; i<=et;i++){ $U=read (); v=read (); $ if(U>m | | v>m)Continue; -mp[u][v]=mp[v][u]=1; - } thememset (link,-1,sizeoflink); - intans=solve ();Wuyiprintf"%d\n", ans); the return 0; -}
Rokua P3386 "template" binary map matching