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

我可怜的SPFA啊?为啥你老是害我啊

Posted by jiangke at 2010-04-17 17:14:16 on Problem 2516
咱这题用最小费用流的,spfa时非常好心的希望及时跳出,所以自以为是的加了个判断

int pathNext(){
	queue<int> Q;
	memset(vis,0,sizeof(vis));
	memset(pre,-1,sizeof(pre));
	int u,v;
	for(v=s;v<=t;v++)
		d[v]=Inf;
	vis[s]=true;
	Q.push(s);
	d[s]=0;
	while(!Q.empty()){
		u=Q.top();
		Q.pop();
		vis[u]=false;
		for(v=s;v<=t;v++){
			if(cap[u][v]>0&&d[v]>d[u]+cost[u][v]){
				d[v]=d[u]+cost[u][v];
				pre[v]=u 
				if(v==t)//我想宰了它
					return d[t];
				if(!vis[v]){
					vis[v]=true;
					Q.push(v);
				}
			}
		}	
	}
		return -1;
}

结果杯具上演了!无数的TLE,逼得我只想跳楼!后来重写没有加那个判断,只是运行到队空,尽然,竟然 神一般的AC了!500多MS!这。。。这怎么回事!!诸位神佛,路过的,飞过的,飘过的,给俺解释解释啊!!谢谢!!

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