Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

30行,438MS的CPP代码

Posted by yousiki at 2016-07-28 16:00:15 on Problem 1466
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 500, M = 20000;
int n, hd[N], to[M], nt[M], vis[N], mc[N], tot, ans;
inline void addEdge(int x, int y) {
	nt[tot] = hd[x], to[tot] = y, hd[x] = tot++;
}
inline bool find(int u) {
	for (int i = hd[u]; ~i; i = nt[i])if (!vis[to[i]] && (vis[to[i]] = 1))
		if (mc[to[i]] == -1 || find(mc[to[i]])) {
			mc[to[i]] = u;
			return true;
		}
	return false;
}
signed main(void) {
	while (scanf("%d", &n) != EOF) {
		memset(mc, -1, n << 2);
		memset(hd, -1, n<<2), tot = 0;
		for (int i = 0, x, y, z; i < n; i++) {
			scanf("%d: (%d)", &x, &y);
			for (int j = 0; j < y; j++)
				scanf("%d", &z), addEdge(x, z);
		}
		for (ans = tot = 0; tot < n; tot++)
			memset(vis, 0, sizeof(vis)), ans += find(tot);
		printf("%d\n", n - (ans >> 1));
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator