zoukankan      html  css  js  c++  java
  • hdu1083完备匹配的判定

    直接上代码。

    /*
     * hdu1083/win.cpp
     * Created on: 2012-8-16
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    const int MAXN = 305;
    vector<int> mymap[MAXN];
    int N, M, mymatch[MAXN];
    bool visited[MAXN];
    void init() {
        for(int i = 0; i < N; i++) {
            mymap[i].clear();
        }
    }
    bool dfs(int k) {
        int t, I;
        for(int i = 0; i < (int)mymap[k].size(); i++) {
            I = mymap[k][i];
            if(!visited[I]) {
                visited[I] = true;
                t = mymatch[I];
                mymatch[I] = k;
                if(t == -1 || dfs(t)) {
                    return true;
                }
                mymatch[I] = t;
            }
        }
        return false;
    }
    int hungary () {
        memset(mymatch, -1, sizeof(mymatch));
        int ans = 0;
        for (int i = 0; i < N; i++) {
            memset(visited, false, sizeof(visited));
            if (dfs(i)) {
                ans++;
            }
        }
        return ans;
    }
    bool buildgraph() {
        int t, K;
        init();
        for (int i = 0; i < N; i++) {
            scanf("%d", &K);
            for(int k = 0; k < K; k++) {
                scanf("%d", &t);
                mymap[i].push_back(t - 1);
            }
        }
        return true;
    }
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int T, P;
        scanf("%d", &T);
        while(T--) {
            scanf("%d%d", &N, &P);
            buildgraph();
            puts(hungary() == N ? "YES" : "NO");
        }
        return 0;
    }
  • 相关阅读:
    7、cad图纸打印
    对账
    练习10—去掉图片文字
    6、cad里面如何快速将图纸的线条全部变成黑色
    5、cad如何快速选中图纸上所有文字
    4、如何修改cad的背景色为白色
    练习九—快速修饰面部光影
    iOS alloc&init探索
    export default / export const
    Vue2.0+组件库总结
  • 原文地址:https://www.cnblogs.com/moonbay/p/2642042.html
Copyright © 2011-2022 走看看