One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.
Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.
Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?
寒假到了,N头牛都要去参加一场在编号为X(1≤X≤N)的牛的农场举行的派对(1≤N≤1000),农场之间有M(1≤M≤100000)条有向路,每条路长Ti(1≤Ti≤100)。
每头牛参加完派对后都必须回家,无论是去参加派对还是回家,每头牛都会选择最短路径,求这N头牛的最短路径(一个来回)中最长的一条路径长度。
第一行三个整数N,M, X;
第二行到第M+1行:每行有三个整数Ai,Bi, Ti ,表示有一条从Ai农场到Bi农场的道路,长度为Ti。
输出格式:
一个整数,表示最长的最短路得长度。
a数组求得由源点出发的最短路
b数组将a数组中的所有路反向再求一次即为各点到源点的最短路。
相加求max即可
附代码。蒟蒻代码大神勿喷
var
n,m,x,i,j,k,q,y,z,l,r,max:longint;
a,b:array[1..1000,1..1000]of longint;
dis,line,sum:array[1..10000]of longint;
bo:array[1..1000]of boolean;
procedure doit(x:longint);
var
i,j,k,t:longint;
begin
for i:=1 to n do
begin
if (i<>x)and(a[x,i]+dis[x]
bo[x]:=false;
end;
procedure doit2(x:longint);
var
i,j,k,t:longint;
begin
for i:=1 to n do
begin
if (i<>x)and(b[x,i]+dis[x]
bo[x]:=false;
end;
begin
readln(n,m,x);
for i:=1 to n do
for j:=1 to n do
begin
a[i,j]:=maxlongint div 3;
b[i,j]:=maxlongint div 3;
end;
for i:=1 to n do
begin
a[i,i]:=0;
b[i,i]:=0;
dis[i]:=maxlongint div 3;
end;
fillchar(bo,sizeof(bo),false);
for i:=1 to m do
begin
readln(q,y,z);
if a[q,y]>z then a[q,y]:=z;
if b[y,q]>z then b[y,q]:=z;
end;
dis[x]:=0;
l:=1;
r:=1;
line[1]:=x;
bo[x]:=true;
while l<=r do
begin
doit(line[l]);
inc(l);
end;
sum:=dis;
for i:=1 to n do
dis[i]:=maxlongint div 3;
dis[x]:=0;
l:=1;r:=1;
line[1]:=x;
fillchar(bo,sizeof(bo),false);
bo[x]:=true;
while l<=r do
begin
doit2(line[l]);
inc(l);
end;
max:=0;
for i:=1 to n do
begin
if (max
end;
writeln(max);
end.