There is nothing to say, is one side of the property side props to build a two-point diagram, the two attributes are connected to the props, and then enumeration matching, if not match on the output, timestamp optimization
#include <iostream> #include <cstdio> #include <cstring>using namespace Std;const int N=1000005;int N, x,y,h[n],cnt,lk[n],v[n],ti;struct qwe{int ne,to;} E[n<<1];int read () {int r=0,f=1; Char P=getchar (); while (p< ' 0 ' | | P> ' 9 ') {if (p== '-') f=-1; P=getchar (); } while (p>= ' 0 ' &&p<= ' 9 ') {r=r*10+p-48; P=getchar (); } return r*f;} void Add (int u,int v) {cnt++; E[cnt].ne=h[u]; E[cnt].to=v; h[u]=cnt;} bool Dfs (int u) {for (int i=h[u];i;i=e[i].ne) if (v[e[i].to]!=ti) {v[e[i].to]=ti; if (!lk[e[i].to]| | DFS (Lk[e[i].to])) {lk[e[i].to]=u; return 1; }} return 0;} int main () {n=read (); for (int i=1;i<=n;i++) {int x=read (), Y=read (); Add (X,i), add (y,i); } for (int i=1;i<=10001;i++) {ti++; if (!dfs (i)) {printf ("%d\n", i-1); Break }} return 0;}
Bzoj 1854: [Scoi2010] Game "Hungarian algorithm"