It's a magical way ... In Ponder
1 /**/2#include <iostream>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <algorithm>7#include <vector>8 using namespacestd;9 Const intmxn=12000;Tenvector<int>E[MXN]; One intLINK[MXN],VIS[MXN]; A BOOLMK[MXN]; - intn,r,c; - voidinit () { the for(intI=1; i<mxn;i++) e[i].clear (); -memset (Link,0,sizeoflink); - } - BOOLDfsintx) { + inti,j; -mk[x]=1; + for(i=0; I<e[x].size (); i++){ A intv=E[x][i]; at if(!Vis[v]) { -vis[v]=1; -mk[v]=1; - if(!link[v] | |DFS (Link[v])) { -link[v]=x; -link[x]=v; in return 1; - } to } + } - return 0; the } * voidpath () { $ inti,j;Panax NotoginsengMemset (MK,0,sizeofmk); - for(i=1; i<=r;i++){ the if(!Link[i]) { +memset (Vis,0,sizeofvis); A DFS (i); the } + } - for(i=1; i<=r;i++){ $ if(!Mk[i]) { $printf"r%d", i); - } - } the for(i=1; i<=c;i++){ - if(mk[i+R]) {Wuyiprintf"c%d", i); the } - } Wuprintf"\ n"); - return; About } $ intMain () { - while(SCANF ("%d%d%d", &r,&c,&n) && R && C &&N) { - init (); - inti,j; A intx, y; + for(i=1; i<=n;i++){ thescanf"%d%d",&x,&y); -E[x].push_back (y+R); $e[y+r].push_back (x); the } the intans=0; the for(i=1; i<=r;i++) {//first match, calculate the answer thememset (Vis,0,sizeofvis); - if(Dfs (i)) ans++; in } theprintf"%d", ans); thePath ();//Calculate Path About } the return 0; the}
UVa 11419 SAM I AM