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

麻烦看下哪里错了~~3Q

Posted by ymh at 2010-02-15 21:13:26 on Problem 3662
var q,w,e,i,j,l,r,mid,n,m:longint;
a,aa:array[0..1000,0..1000] of longint;
f:array[0..1000]of boolean;
dist:array[0..1000] of longint;

function check(zhi:longint):boolean;
var
i,j,min,m:longint;
begin
        for i:=1 to q do
        for j:=1 to q do
        begin
                if (aa[i,j]>zhi)and(aa[i,j]<>maxlongint) then a[i,j]:=1;
                if aa[i,j]=maxlongint then a[i,j]:=maxlongint;
                if aa[i,j]<=zhi then a[i,j]:=0;
        end;

        for i:=1 to q do
        dist[i]:=maxlongint;
        dist[1]:=0;
        fillchar(f,sizeof(f),false);
	for i:=1 to q-1 do
	begin
		min:=maxlongint;
		for j:=1 to q do if not(f[j])and(dist[j]<min) then
		begin
			min:=dist[j];
			m:=j;
		end;
		f[m]:=true;
		for j:=1 to q do
                if not(f[j])and(a[m,j]<>maxlongint)and(dist[m]+a[m,j]<dist[j]) then
		dist[j]:=a[m,j]+dist[m];
        end;

        if (zhi=0)and(dist[q]=maxlongint) then
        begin
                writeln(-1);
                halt;
        end;

        if dist[q]>e then exit(false)
        else exit(true);
end;


begin
        readln(q,w,e);
        for i:=1 to q do
        for j:=1 to q do
                aa[i,j]:=maxlongint;
        for i:=1 to w do
        begin
                read(n,m,aa[n,m]);
                aa[m,n]:=aa[n,m];
        end;

        check(0);

        begin
                r:=maxlongint;
                while l<r do
                begin
                        mid:=(l+r) div 2;
                        if not check(mid) then l:=mid+1
                        else r:=mid;
                end;

        writeln(mid);
        end;
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