问题描述: |
顺利通过了黄药师的考验,下面就可以尽情游览桃花岛了! | |
数据输入: |
第1行为5个整数:n、m、s、t、t0,分别表示点数,边数,岛西头的编号,岛东头的编号(编号是从1到n)和你乘船从岛东头到西头一次的时间。
| |
结果输出: |
假设总耗时为total,则输出total mod 10000的值(total对10000取余)。 | |
样例: |
3 4 1 3 7 1 2 5 2 3 7 2 3 10 1 3 15 |
56 |
核心思想: |
拓扑排序 |
type
edge=record
y,next,d:longint;
end;
var
a:array[0..50010]of edge;
first,d,v,w:array[0..10010]of longint;
q:array[0..1000000]of longint;
n,m,s,t,t0,tot,sum,ans:longint;
//==============================================
procedure build(x,y,d:longint);
begin
inc(tot);
a[tot].y:=y;
a[tot].d:=d;
a[tot].next:=first[x];
first[x]:=tot;
end;
//===========================================
procedure init;
var
i,x,y,d:longint;
begin
tot:=0;
readln(n,m,s,t,t0);
for i:=1 to m do
begin
readln(x,y,d);
build(x,y,d);
inc(v[y]);
end;
tot:=0;
end;
procedure tp;
var
head,tail,i:longint;
begin
fillchar(d,sizeof(d),0);
fillchar(w,sizeof(w),0);
fillchar(q,sizeof(q),0);
head:=1;tail:=1;
w[s]:=1;q[1]:=s;d[s]:=0;
while head<=tail do
begin
tot:=first[q[head]];
while tot>0 do
begin
dec(v[a[tot].y]);
d[a[tot].y]:=((d[q[head]]+d[a[tot].y])mod 10000+(a[tot].d*w[q[head]])mod 10000)mod 10000;{<到达该点路程和>}
w[a[tot].y]:=(w[a[tot].y]+w[q[head]])mod 10000;{<到达该点的方案和>}
if v[a[tot].y]=0 then
begin
inc(tail);
q[tail]:=a[tot].y;
end;
tot:=a[tot].next;
end;
inc(head);
end;
end;
begin
assign(input,'p1331.in');reset(input);
assign(output,'p1331.out');rewrite(output);
init;
tp;
writeln((d[t]+(w[t]-1)*t0) mod 10000);
close(input);close(output);
end.