Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
ANS=N-最大匹配,附25行代码#include<cstdio> #include<cstring> #include<cstdlib> using namespace std; const int N = 155; int T, t, n, m, G[N][N], mch[N], vis[N], ans, x, y; inline bool find(int u) { for (int i = 1; i <= n; i++)if (G[u][i] && !vis[i] && (vis[i] = 1)) if (mch[i] == -1 || find(mch[i])) { mch[i] = u; return true; } return false; } signed main(void) { for (scanf("%d", &T), t = 1; t <= T; t++) { memset(G, 0, sizeof(G)); memset(mch, -1, sizeof(mch)); for (scanf("%d%d", &n, &m); m; m--) scanf("%d%d", &x, &y), G[x][y] = 1; for (x = 1, ans = 0; x <= n; x++) memset(vis, 0, sizeof(vis)),ans += find(x); printf("%d\n", n - ans); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator