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

discuss里数据都过了,但是交还是WA

Posted by xyf at 2012-05-21 16:19:28 on Problem 1087
我是这样网络流的
S,T为99998 和99999
一开始有N种插头,全部连S。 出现一次流量就是1,出现2次流量就是2.

后来的M个用电器,都连T。 出现1次流量是1,2次就是2。。

插头,插座的编号是一起的。
如果有A插头,也有A用电器,那么就是S ->A -> T

下面的K个配置器 

x,y配置起, 那么   y -> x 流量为无穷大


各种帖子的数据全过了,我数组开那么大也不是数组问题把。求破

ps :  g++
c++就编译失败了,为什么呢

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

#define CLR(a,b) memset(a, b, sizeof(a))

const int max_char = 5000;
const int max_n = 100000;
const int inf = 0x7fffffff;

int n,m,k;
char ts[max_char];
map<string, int>h, g, num;
map<string, int>:: iterator it;
map<string, int>:: iterator it2;
string s;
int tot = 0;
int S = 99998, T = 99999;


int now[max_n], next[max_n], pre[max_n], flow[max_n], dot[max_n], tail = 0;


void init();
void getmun(const string &);
void doit();
void insert(int, int, int);



int main()
{
	while (scanf("%d", &n) != EOF)
	{
		init();
		doit();
	}
	return 0;
}

void getnum(const string &x)
{
	it = num.find(x);
	if (it != num.end()) return;
	num[x] = ++ tot;
}


void insert(int a,int b,int c)
{
	++ tail;
	dot[tail] = b;
	flow[tail] = c;
	next[tail] = now[a];
	now[a] = tail;
	pre[tail] = ++ tail;

	dot[tail] = a;
	flow[tail] = 0;
	next[tail] = now[b];
	now[b] = tail;
	pre[tail] = tail - 1;
}


void init()
{
	CLR(flow, 0);
	CLR(next, 0);
	CLR(now, 0);
	CLR(dot, 0);
	h.clear();
	g.clear();
	num.clear();
	tot = 0;

	for (int i = 1; i <= n; ++ i)
	{
		scanf("%s", ts);
		s = ts;
		it = h.find(s)	;
		if (it != h.end())	++ h[s];
		else h[s] = 1;
		getnum(s);
	}
	scanf("%d\n", &m);
	for (int i = 1; i <= m; ++ i)
	{
		scanf("%s ", ts);
		scanf("%s", ts);
		s = ts;
		it = g.find(s);
		if (it != g.end())	++ g[s];
		else g[s] = 1;
		getnum(s);
	}

	for (it = num.begin(); it != num.end(); ++ it)
	{
		int tmp = (*it).second;
		s = (*it).first;
		it2 = h.find(s);
		if (it2 != h.end()) insert(S, tmp, (*it2).second);
		it2 = g.find(s);
		if (it2 != g.end()) insert(tmp, T, (*it2).second);
	}
	scanf("%d\n", &k);
	for (int i = 1; i <= k; ++ i)
	{
		int x,y;
		scanf("%s", ts);
		s = ts;
		getnum(s);
		it = num.find(s);		
		x = (*it).second;
		scanf("%s", ts);
		s = ts;
		getnum(s);
		it = num.find(s);
		y = (*it).second;
		insert(y, x, inf);
	}
	tot = num.size() + 2;
}


int H[max_n] = {0};
int d[max_n] = {0};

int sap(int u,int FF)
{
	int ans = 0;
	if (u == T) return FF;
	for (int i = now[u]; i; i = next[i])
	{
		int will = dot[i];
		if (flow[i] && d[u] == d[will] + 1)
		{
			int tmp = sap(will, min(FF - ans, flow[i]));
			flow[i] -= tmp;
			flow[pre[i]] += tmp;
			ans += tmp;
			if (ans == FF) return FF;
		}
	}
	if (d[S] >= tot) return ans;
	if (! --H[d[u]]) d[S] = tot;
	++ H[++d[u]];
	return ans;
}



void doit()
{
	CLR(H, 0);
	CLR(d, 0);
	int ans = 0;
	for(H[0] = tot; d[S] < tot ;)	ans += sap(S, inf);
	printf("%d\n", m - ans);
}

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