HDU 2444 二分图判定+最大匹配

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2444
用模拟上色来判定了。然后判定完再用最大匹配就好了。
尴尬的是No打成NO,WA了1个小时找不到错。尴尬

#include
#define INF 1e18
#define inf 1e9
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
const int _max = 205;
bool mp[_max][_max],vis[_max];
int n,m,link[_max],col[_max];

bool judge(int i,int co){
    col[i] = co;
    for(int j = 1 ; j <= n ; j++){
        if(!mp[i][j]) continue;
        if(!col[j]){
            if(!judge(j,-co)) return 0;
        }
        else if(col[i] == col[j]) return 0;
    }
    return 1;
}
bool isBigraph(){
    memset(col,0,sizeof(col));
    for(int i = 1 ; i <= n ; i++){
        if(col[i]==0){
            if(!judge(i,-1)) return 0;
        } 
    }
    return 1;
}
bool dfs(int rt){
    for(int i = 1 ; i <= n ; i++){
        if(!mp[rt][i] || !vis[i]) continue;
        vis[i] = 0;
        if(link[i] == 0 || dfs(link[i])){
            link[i] = rt;
            return true;
        }
    }
    return false;
}
int hungary(){
    int res = 0;
    memset(link,0,sizeof(link));
    for(int i = 1 ; i <= n ; i++){
        memset(vis,1,sizeof(vis));
        if(dfs(i)) res++;
    }   
    return res;
}
int main(){
    IOS;
    int u,v;
    while(cin>>n>>m){
        memset(mp,0,sizeof(mp));
        for(int i = 1 ; i <= m ; i++){
            cin>>u>>v;
            mp[u][v] = 1;
            mp[v][u] = 1;
        }
        if(!isBigraph()) cout<<"No"<else cout<2<return 0;
}

你可能感兴趣的:(HDOJ,二分图匹配,HDOJ,二分图判定,最大匹配)