到了算法会写,但看不懂题目要用啥算法的阶段……真是悲哀
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 100
int n, m, k;
typedef struct _Node{
int to;
struct _Node* next;
}Node, *pNode;
pNode map[M];
int match[M];
int visited[M];
int DFS(int k){
pNode p = map[k];
int t;
while(p){
if(visited[p->to]){
p = p->next;
continue;
}
else
visited[p->to] = 1;
t = match[p->to];
match[p->to] = k;
if(t==-1 || DFS(t))
return 1;
match[p->to] = t;
p = p->next;
}
return 0;
}
int cal(){
int i, sum = 0;
memset(match, -1, sizeof(match));
for(i=0; i<n; i++){
if(!map[i]) continue;
memset(visited, 0, sizeof(visited));
if(DFS(i))
sum++;
}
return sum;
}
int main() {
int i, t, u, v;
pNode p;
freopen("in", "r", stdin);
while(scanf("%d", &n), n){
scanf("%d %d", &m, &k);
memset(map, 0, sizeof(map));
for(i=0; i<k; i++){
scanf("%d %d %d", &t, &u, &v);
if(!u || !v) continue;
p = (pNode)malloc(sizeof(Node));
p->to = v;
p->next = map[u];
map[u] = p;
}
printf("%d\n", cal());
}
return 0;
}