标签:
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<queue> #include<cmath> using namespace std; #define INF 0x3fffffff #define maxn 1705 int n, P[maxn], Head[maxn], m, k; bool vis[maxn]; struct EdgeNode { int e, next; }edge[maxn*5]; void AddEdge(int s, int e) { edge[k].next = Head[s]; edge[k].e = e; Head[s] = k ++; } void DFS2(int u) { } bool Find(int u) { for(int i=Head[u]; i!=-1; i=edge[i].next) { int v = edge[i].e; if(!vis[v] ) { vis[v] = true; if(P[v] == -1 || Find(P[v]) ) { P[v] = u; return true; } } } return false; } int solve() { int ans = 0; memset(P, -1, sizeof(P)); for(int i=1; i<=n; i++) { memset(vis, false, sizeof(vis)); if( Find(i) ) ans ++; } return n - ans; } int main() { int T; scanf("%d", &T); while(T--) { scanf("%d %d",&n, &m); int a, b; k = 0; memset(Head, -1, sizeof(Head)); for(int i=0; i<m; i++) { scanf("%d %d",&a, &b); AddEdge(a, b); } printf("%d\n", solve() ); } return 0; }
标签:
原文地址:http://www.cnblogs.com/chenchengxun/p/4718599.html