| ||||||||||
| 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 | |||||||||
其实我知道有些题是瞧不起pascal的,你告诉我怎么错了type
edge=record
r,c:double;
v,next:longint;
end;
var
edges:array[1..1000] of edge;
head,times:array[1..1000] of longint;
dist:array[1..1000] of double;
q:array[1..100000] of longint;
flag:array[1..1000] of boolean;
p,m,n,i,tot,x,y:longint;
sm,r1,r2,c1,c2:double;
procedure add(x,y:longint; r1,c1,r2,c2:double);
begin
inc(tot);
edges[tot].v:=y;
edges[tot].r:=r1;
edges[tot].c:=c1;
edges[tot].next:=head[x];
head[x]:=tot;
inc(tot);
edges[tot].v:=x;
edges[tot].r:=r2;
edges[tot].c:=c2;
edges[tot].next:=head[y];
head[y]:=tot;
end;
function spfa(x:double):boolean;
var
s,t,tmp,go,k:longint;
begin
fillchar(flag,sizeof(flag),false); fillchar(dist,sizeof(dist),0);
fillchar(q,sizeof(q),0); fillchar(times,sizeof(times),0);
q[1]:=n; dist[1]:=x; flag[n]:=true; s:=1; t:=2; times[n]:=1;
while s<>t do
begin
k:=q[s];
inc(s);
if s>100000 then s:=1;
flag[k]:=false;
tmp:=head[k];
while tmp<>-1 do
begin
go:=edges[tmp].v;
if dist[go]<(dist[k]-edges[tmp].c)*edges[tmp].r then
begin
dist[go]:=(dist[k]-edges[tmp].c)*edges[tmp].r;
inc(times[go]);
if times[go]>p then exit(true);
if flag[go]=false then
begin
q[t]:=go;
inc(t);
if t>100000 then t:=1;
flag[go]:=true;
end;
end;
tmp:=edges[tmp].next;
end;
end;
exit(false);
end;
begin
readln(p,m,n,sm); tot:=0;
fillchar(edges,sizeof(edges),0); fillchar(head,sizeof(head),255);
for i:=1 to m do
begin
readln(x,y,r1,c1,r2,c2);
add(x,y,r1,c1,r2,c2);
end;
if spfa(sm) then writeln('YES') else writeln('NO');
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator