Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- edge = record
- a,b,cost:longint;
- end;
- const
- count = 1000;
- inf = 1000000;
- var
- e:array[1..count] of edge;
- d:array[1..count] of longint;
- i,j,n,m,v1,v2:longint;
- Begin
- read(n,m,v1,v2);
- for i:=1 to m do
- read(e[i].a,e[i].b,e[i].cost);
- for i:=1 to n do
- d[i]:=inf;
- d[v1]:=0;
- for i:=1 to n do
- for j:=1 to m do
- if (d[e[j].b] > d[e[j].a] + e[j].cost) and (d[e[j].a] < inf) then
- d[e[j].b] := d[e[j].a] + e[j].cost;
- write(d[v2]);
- end.
Advertisement
Add Comment
Please, Sign In to add comment