BZOJ#1191[HNOI2006] 超级英雄 Hero

[HNOI2006] 超级英雄 Hero

image

思路:

每个题都只有两种答案,选择一种以后再不能选择,匈牙利模板

代码:

#include <bits/stdc++.h>
#define int long long
int _= 0, Case = 1;
using namespace std;
#define all(v) begin(v),end(v)
#define nline '\n'

const int N=2010;
int match[N],st[N];
vector<int> h[N];
bool find(int u){
    for(auto i:h[u]){
        if(!st[i]){
            st[i]=true;
            if(!match[i] or find(match[i])){
                match[i]=u;
                return true;
            }
        }
    }
    return false;
}
void solve(int Case) {
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        a++,b++;
        h[i].push_back(a+m);
        h[i].push_back(b+m);
    }
    for(int i=1;i<=m;i++){
        for(int j=m+1;j<=n+m;j++){
            st[j]=false;
        }
        if(!find(i)){
            cout<<i-1<<nline;
            return;
        }
    }
    cout<<m<<nline;
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
 //   cin >> _; for (Case = 1; Case <= _; Case++)
        solve(Case);

    return 0;
}
posted @ 2022-03-30 16:22  指引盗寇入太行  阅读(19)  评论(0编辑  收藏  举报