#include <stdio.h> #include <string.h> #include <conio.h> #define N 125 int g[N][N], used[N], mat[N]; int noi, match;
int find(int k) { int i, j; for(i=1; i<= g[k][0]; i++) { j = g[k][i]; if(!used[j]) { used[j] = 1; if(!mat[j] || find(mat[j])) { mat[j] = k; return 1; } } } return 0; }
void hungary() { int i; for(i=1; i<= noi; i++) { match += find(i); memset(used, 0, sizeof(used)); } }
int main() { int i, j; int t, nos, start, end; freopen("in.txt", "r", stdin); scanf("%d", &t); while(t--) { scanf("%d%d", &noi, &nos); memset(g, 0, sizeof(g)); memset(mat, 0, sizeof(mat)); for(i=1; i<=nos; i++) { scanf("%d%d", &start, &end); g[start][++g[start][0]] = end; } match = 0; hungary(); printf("%d\n", noi-match); } getch(); return 0; }
Problem: |
|
User: |
Memory: 220K |
|
Time: 0MS |
Language: C++ |
|
Result: Accepted |
|