[Topic link]
https://www.lydsy.com/JudgeOnline/problem.php?id=1059
Algorithm
Maximum matching of binary graphs
Complexity of Time: O (n^3)
Code
#include <bits/stdc++.h>using namespacestd;#defineMAXN 210structedge{intto, NXT;} E[MAXN*MAXN];intn, tot;intMATCH[MAXN],HEAD[MAXN];BOOLvisited[maxn];template<typename t> InlinevoidChkmax (T &x,t y) {x =Max (x, y);} Template<typename t> InlinevoidChkmin (T &x,t y) {x =min (x, y);} Template<typename t> InlinevoidRead (T &x) {T F=1; x =0; Charc =GetChar (); for(;!isdigit (c); c = GetChar ())if(c = ='-') F =-F; for(; IsDigit (c); c = GetChar ()) x = (x <<3) + (x <<1) + C-'0'; X*=F;} InlinevoidAddedge (intUintv) {Tot++; E[tot]=(Edge) {V,head[u]}; Head[u]=tot;} InlineBOOLHungaryintu) { for(inti = Head[u]; I i =e[i].nxt) { intv =e[i].to; if(!Visited[v]) {Visited[v]=true; if(!match[v] | |Hungary (Match[v])) {Match[v]=u; return true; } } } return false;}intMain () {intT; Read (T); while(t--) {read (n); Tot=0; for(inti =1; I <= N; i++) Head[i] =0; for(inti =1; I <= N; i++) { for(intj =1; J <= N; J + +) { intx; Read (x); if(x = =1) Addedge (I,J); }} memset (Match,0,sizeof(match)); intt =0; for(inti =1; I <= N; i++) {memset (visited,false,sizeof(visited)); if(Hungary (i)) T++; } if(t = = N) printf ("yes\n"); Elseprintf"no\n"); } return 0; }
[Zjoi 2007] Matrix game