'commit'
This commit is contained in:
51
TangDou/AcWing/ErFenTu/376.cpp
Normal file
51
TangDou/AcWing/ErFenTu/376.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
const int N = 2 * 110, M = 1010;
|
||||
|
||||
int n, m, k;
|
||||
|
||||
// 链式前向星
|
||||
int e[M], h[N], idx, w[M], ne[M];
|
||||
void add(int a, int b, int c = 0) {
|
||||
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
|
||||
}
|
||||
|
||||
// 匈牙利算法模板
|
||||
int match[N], st[N];
|
||||
int find(int u) {
|
||||
for (int i = h[u]; ~i; i = ne[i]) {
|
||||
int v = e[i];
|
||||
if (!st[v]) {
|
||||
st[v] = 1;
|
||||
if (!match[v] || find(match[v])) {
|
||||
match[v] = u;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
while (scanf("%d", &n), n) {
|
||||
scanf("%d %d", &m, &k);
|
||||
memset(match, 0, sizeof match);
|
||||
memset(h, -1, sizeof h);
|
||||
idx = 0;
|
||||
while (k--) {
|
||||
int t, a, b;
|
||||
scanf("%d %d %d", &t, &a, &b);
|
||||
if (!a || !b) continue; // 0状态不用处理
|
||||
add(a, b); // 此边是一个任务
|
||||
}
|
||||
|
||||
int res = 0;
|
||||
for (int i = 1; i < n; i++) {
|
||||
memset(st, 0, sizeof st);
|
||||
if (find(i)) res++;
|
||||
}
|
||||
printf("%d\n", res);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user