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

通过了官方的测试数据,却在OJ上WA了,求助!!!

Posted by whitetooth at 2012-04-12 13:01:32 on Problem 3155
Program POJ_3155;
Const
	maxn						=1100+1;
	maxm						=6200;
	inf							=1<<27;
	eps							=1e-6;
Var
	a,b							:array[0..1000] of longint;
	pre,other					:array[0..maxm] of longint;
	flow						:array[0..maxm] of double;
	last,can					:array[0..maxn] of longint;
	dist,sum,prev				:array[0..maxn] of longint;
	tmp							:array[0..maxn] of double;
	node						:array[0..maxn] of longint;
	vis							:array[0..maxn] of boolean;
	n,m,i						:longint;
	l,s,t						:longint;
	cnt							:longint;
	
Procedure Swap(Var x,y:longint);
Var temp						:longint;
Begin
	temp:=x; x:=y; y:=temp;
End;
	
Procedure Init;
Begin
	read(n,m);
	if m=0 then
		begin
			writeln(1);
			writeln(1);
			halt;
		end;
	s:=0; t:=n+m+1;
	for i:=1 to m do read(a[i],b[i]);
End;

Procedure In_Path(p,q:longint;r:double);
Begin
	inc(l); pre[l]:=last[p]; last[p]:=l; other[l]:=q; flow[l]:=r;
	inc(l); pre[l]:=last[q]; last[q]:=l; other[l]:=p; flow[l]:=0;
End;
	
Function Max_Flow:double;
Var p,q,min,k					:longint;
	inflow,ans					:double;
	flag						:boolean;
Begin
	ans:=0;
	for i:=s to t do can[i]:=last[i];
	fillchar(dist,sizeof(dist),0);
	fillchar(sum,sizeof(sum),0);
	sum[0]:=t+1;
	i:=s; inflow:=inf;
	while dist[s]<=t do
		begin
			flag:=false;
			tmp[i]:=inflow;
			p:=can[i];
			while p<>-1 do
				begin
					q:=other[p];
					if (flow[p]>0)and(dist[i]=dist[q]+1) then
						begin
							flag:=true;
							if flow[p]<inflow then inflow:=flow[p];
							can[i]:=p;
							prev[q]:=p;
							i:=q;
							if i=t then
								begin
									ans:=ans+inflow;
									while i<>s do
										begin
											p:=prev[i];
											flow[p]:=flow[p]-inflow;
											flow[p xor 1]:=flow[p xor 1]+inflow;
											i:=other[p xor 1];
										end;
									inflow:=inf;
								end;
							break;
						end;
					p:=pre[p];
				end;
			if flag then continue;
			min:=t+1;
			p:=last[i];
			while p<>-1 do
				begin
					q:=other[p];
					if (flow[p]>0)and(dist[q]<min) then
						begin
							min:=dist[q];
							k:=p;
						end;
					p:=pre[p];
				end;
			can[i]:=k;
			dec(sum[dist[i]]);
			if sum[dist[i]]=0 then break;
			dist[i]:=min+1;
			inc(sum[dist[i]]);
			if i<>s then
				begin
					i:=other[prev[i] xor 1];
					inflow:=tmp[i];
				end;
		end;
	exit(ans);
End;

Function Check(x:double):boolean;
Begin
	fillchar(last,sizeof(last),255);
	l:=-1;
	for i:=1 to n do in_path(i,t,x);
	for i:=1 to m do in_path(s,n+i,1);
	for i:=1 to m do
		begin
			in_path(n+i,a[i],inf);
			in_path(n+i,b[i],inf);
		end;
	exit(m-max_flow>eps);
End;

Procedure Main;
Var l,r,mid						:double;
Begin
	l:=0; r:=m;
	while r-l>eps do
		begin
			mid:=(l+r)*0.5;
			if check(mid) then l:=mid
			else r:=mid;
		end;
	check(l);
End;

Procedure Dfs(x:longint);
Var p,q							:longint;
Begin
	vis[x]:=true;
	p:=last[x];
	while p<>-1 do
		begin
			q:=other[p];
			if (flow[p]>0)and(not vis[q]) then dfs(q);
			p:=pre[p];
		end;
	if (x>=1)and(x<=n) then
		begin
			inc(cnt);
			node[cnt]:=x;
		end;
End;

Procedure Print;
Var p,q							:longint;
Begin
	cnt:=0;
	dfs(s);
	for p:=1 to cnt-1 do
		for q:=cnt downto p+1 do
			if node[q]<node[q-1] then
				swap(node[q],node[q-1]);
	writeln(cnt);
	for i:=1 to cnt do writeln(node[i]);
End;

Begin
	Init;
	Main;
	Print;
End.

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