二分图 : 最小点覆盖

机器任务

最小点覆盖

#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PII pair<int, int>
#define x first
#define y second
#define inf 0x3f3f3f3f
const int N = 110;
int n, m, k;
int match[N];
bool g[N][N], st[N];

bool find(int x) {
    for (int i = 0; i < m; ++i)
        if (!st[i] && g[x][i]) {
            st[i] = true;
            if (match[i] == -1 || find(match[i])) {
                match[i] = x;
                return true;
            }
        }
    return false;
}

int main() {
    IO; 
    while (cin >> n, n) {
        cin >> m >> k;
        memset(g, 0, sizeof g);
        memset(match, -1, sizeof match);
        while (k--) {
            int t, a, b;
            cin >> t >> a >> b;
            if (!a || !b) continue;
            g[a][b] = true;
        }
        int res = 0;
        for (int i = 0; i < n; ++i) {
            memset(st, 0, sizeof st);
            if (find(i)) res++;
        }
        cout << res << '\n';
    }
    return 0;
}

posted @ 2021-02-22 17:07  phr2000  阅读(44)  评论(0编辑  收藏  举报