Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
N囧IP暴0,刷到水题发泄发泄…………贴代码 #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #define maxn 205 #define max(a,b) (((a)>(b))?(a):(b)) int adj[maxn][maxn]; int dx[maxn],dy[maxn],mx[maxn],my[maxn]; int q[maxn+maxn]; int n,m,ff,rr,ans; bool bfs(){ bool ans=false; memset(q,0,sizeof(q)); ff=rr=0; for(int i=1;i<=n;i++) if(mx[i]+1==0) q[++ff]=i; for(int i=1;i<=n;i++) dx[i]=dy[i]=0; for(;rr<ff;){ int u=q[++rr]; for(int i=1;i<=adj[u][0];i++){ int v=adj[u][i]; if(dy[v]==0){ dy[v]=dx[u]+1; if(my[v]+1==0) ans=true; else dx[my[v]]=dy[v]+1,q[++ff]=my[v]; } } } return ans; } bool dfs(int x){ for(int i=1;i<=adj[x][0];i++){ int y=adj[x][i]; if(dy[y]==dx[x]+1){ dy[y]=0; if((my[y]+1==0)||(dfs(my[y]))) return my[y]=x,mx[x]=y,true; } } return false; } int main(){ for(;scanf("%d%d",&n,&m)!=EOF;ff=rr=ans=0){ memset(adj,0,sizeof(adj)); memset(dx,0,sizeof(dx)); memset(dy,0,sizeof(dy)); memset(mx,0,sizeof(mx)); memset(my,0,sizeof(my)); memset(q,0,sizeof(q)); for(int i=1,j;i<=n;i++) for(j=0,scanf("%d",&adj[i][0]);j<adj[i][0];scanf("%d",&adj[i][++j])); for(int i=1;i<=max(m,n);i++) mx[i]=my[i]=-1; for(;bfs();) for(int i=1;i<=n;i++) if((mx[i]+1==0)&&(dfs(i))) ans++; printf("%d\n",ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator