#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <vector> using namespace std; #define N 101 int match[N]; bool vis[N]; vector <int> e[N]; int n, m, k; void InitRead(); void DataProcess(); bool Dfs(int x); int main() { while (~scanf("%d", &n)) { if (n == 0) break; InitRead(); DataProcess(); } return 0; } void InitRead() { scanf("%d %d", &m, &k); memset(match, -1, sizeof(match)); for (int i=0; i<N; ++i) e[i].clear(); int a, b; for (int i=0; i<k; ++i) { scanf("%*d %d %d", &a, &b); if (a == 0 || b == 0) continue; //可以用模式0解决的任务不建边 e[a].push_back(b); } return; } void DataProcess() { int ans = 0; for (int i=0; i<n; ++i) { memset(vis, false, sizeof(vis)); if (Dfs(i)) ans++; } printf("%d\n", ans); return; } bool Dfs(int x) { int size = e[x].size(); for (int i=0; i<size; ++i) { if (!vis[e[x][i]]) { vis[e[x][i]] = true; if (match[e[x][i]] == -1 || Dfs(match[e[x][i]])) { match[e[x][i]] = x; return true; } } } return false; }
时间: 2024-10-10 06:59:03