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

我是按节点最大数102个建的图,麻烦各位大牛帮我看看哪里出问题了。。测试数据没问题但就是WA。。TAT...不胜感激~~~

Posted by sjyubowen at 2011-02-05 15:12:54 on Problem 1149 and last updated at 2011-02-05 15:15:17
#include <stdio.h>
#include <string.h>

const int MAX = 110;
const int INF = 1000;
bool vis[MAX];
int n, ans, queue[MAX], pre[MAX], map[MAX][MAX];

int min(int x, int y)
{
	return x < y ? x : y;
}

bool bfs()
{
	int i, u, head, tail;
	memset(vis, 0, sizeof(vis));
	head = tail = 1;
	queue[tail++] = 0;
	while (head < tail)
	{
		u = queue[head++];
		for (i = 1; i <= n+1; i++)
			if (!vis[i] && map[u][i])
			{
				pre[i] = u;
				vis[i] = true;
				queue[tail++] = i;
				if (i == n+1)
					return true;
			}
	}
	return false;
}

void compute()
{
	int i, sum;
	sum = INF; 
	for (i = n+1; i != 0; i = pre[i])
		sum = min(sum, map[pre[i]][i]); // 取增广路上最小流量
	for (i = n+1; i != 0; i = pre[i])
	{
		map[pre[i]][i] -= sum;
		map[i][pre[i]] += sum;
	}
	ans += sum;
}

int main()
{
	int i, u, t, m, house[1100], mark[1100];
	scanf("%d%d", &m, &n);
	{
		memset(mark, 0, sizeof(mark));
		memset(map, 0, sizeof(map));
		for (i = 1; i <= m; i++) // 每个猪圈中猪的个数
			scanf("%d", &house[i]);
		for (i = 1; i <= n; i++) // 消费者
		{
			scanf("%d", &t);
			while (t--)
			{
				scanf("%d", &u);
				if (mark[u] == 0) // 猪圈第一次被打开
					map[0][i] += house[u];
				else
					map[mark[u]][i] = INF;
				mark[u] = i;
			}
			scanf("%d", &map[i][n+1]);
		}
		ans = 0;
		while (bfs())
			compute();
		printf("%d\n", ans);
	}
	return 0;
}

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