首页 > 其他 > 详细

BZOJ1191 [HNOI2006]超级英雄Hero

时间:2019-07-25 20:27:22      阅读:67      评论:0      收藏:0      [点我收藏+]

Solution  

  裸的二分图最大匹配,不用多说。

  《论不认真读题的后果》。。。注意一但匹配失败就要break。。。

  Code

技术分享图片
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
inline int read(){
    int x=0;char ch=0;
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x;
}
bool vis[N],Link[N][N]; 
int n,m,match[N];
bool dfs(int x){
    for(int y=0;y<n;++y)
        if(!vis[y]&&Link[x][y]){
            vis[y]=true;
            if(!match[y]||dfs(match[y])){
                match[y]=x;
                return true;
            }
        }
    return false;
}
int hungary(){
    int res=0;
    for(int i=1;i<=m;++i){
        memset(vis,0,sizeof vis);
        if(dfs(i)) ++res;
        else break;
    }
    return res;
}
int main(){
    n=read(),m=read();
    for(int i=1;i<=m;++i){
        int x=read(),y=read();
        Link[i][x]=Link[i][y]=true;
    }
    cout<<hungary()<<endl;
    return 0;
} 
BZOJ1191

 

  

BZOJ1191 [HNOI2006]超级英雄Hero

原文:https://www.cnblogs.com/gosick/p/11246459.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!