| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:几组测试数据In Reply To:Re:几组测试数据 Posted by:stupidjohn at 2010-08-17 20:51:25 > 关键是我没过你的测试数据却拿了AC,想不通
const inf=10000000;maxm=10005;maxn=101;
type
edge=record
y,nx,l,c:longint;
end;
node=record
y,l,c:longint;
end;
var
q:array[0..maxm*10]of node;
head,dis:array[0..maxn]of longint;
f:array[0..maxm]of edge;
n,m,t,r,money,i,x,y,l,c:longint;
procedure swap(i,j:longint);
var tmp:node;
begin
tmp:=q[i];
q[i]:=q[j];
q[j]:=tmp;
end;
procedure add(x,y,l,c:longint);
begin
inc(t);
f[t].y:=y;f[t].nx:=head[x];head[x]:=t;
f[t].l:=l;f[t].c:=c;
end;
procedure insert(x:node);
var i:longint;
begin
inc(r);q[r]:=x;i:=r;
while(i>1)and(q[i shr 1].l>q[i].l)do
begin
swap(i,i shr 1);
i:=i shr 1;
end;
end;
procedure change(x:longint);
var lc,rc,min:longint;
begin
lc:=x+x;rc:=lc+1;
min:=x;
if(lc<=r)and(q[lc].l<q[min].l)then min:=lc;
if(rc<=r)and(q[rc].l<q[min].l)then min:=rc;
if min<>x then
begin
swap(x,min);
change(min);
end;
end;
function get():node;
var res:node;
begin
res:=q[1];
q[1]:=q[r];dec(r);
if r>1 then change(1);
exit(res);
end;
procedure spfa();
var j,y:longint;tmp,new:node;
begin
for i:=1 to n do dis[i]:=inf;
dis[1]:=0;tmp.y:=1;
tmp.l:=0;tmp.c:=0;
insert(tmp);
while r>0 do
begin
new:=get;
dis[new.y]:=new.l;
if new.y=n then exit;
j:=head[new.y];
while j<>-1 do
begin
y:=f[j].y;
if new.c+f[j].c<=money then
begin
tmp.l:=new.l+f[j].l;
tmp.c:=new.c+f[j].c;
tmp.y:=y;
insert(tmp);
end;
j:=f[j].nx;
end;
end;
end;
begin
while not eof do
begin
if eof then break;
readln(money);
fillchar(head,sizeof(head),255);
r:=0;t:=0;
readln(n);readln(m);
for i:=1 to m do
begin
readln(x,y,l,c);
add(x,y,l,c);
end;
spfa();
if dis[n]=inf then writeln(-1)
else writeln(dis[n]);
end;
end.
过了
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator