工厂的烦恼

来源:互联网 发布:javascript语言特点 编辑:程序博客网 时间:2024/05/16 18:24

工厂的烦恼

Time Limit:10000MS  Memory Limit:65536K
Total Submit:91 Accepted:57
Case Time Limit:1000MS

Description

  某工厂发现厂里的机器在生产产品时要消耗大量的原材料,也就是说,有大量的原材料变成了废物。因此厂里想找出消耗原材料最大的一条生产线路进行改造,以降低成本。厂里的生产线路是一个有向无环网络,有N台机器分别代表网络中的N个结点。弧< I,j >(i < j)表示原材料从机器i传输到机器j的损耗数量。

Input

第一行是两个整数N,M(N<=100,M<=1000),分别表示网络的结点个数和弧数。第二行至M+1行,每行三个整数A,B,C,表示弧上的损耗为C。

Output

仅一个整数,为损耗最大的线路的损耗量。

Sample Input

5 51 2 22 4 91 3 73 4 14 5 6

Sample Output

17


用floyd求最长,把小于号改成大于号。


  • const  maxn=100;var  a:array[0..maxn,0..maxn] of longint;  i,j,k,n,m,s,max:longint;begin  readln(n,m);  for i:=1 to m do    begin      readln(j,k,s);      a[j,k]:=s;    end;  for k:=1 to n do    for i:=1 to n do      for j:=1 to n do        if (i<>j) and (i<>k) and (j<>k) then          if a[i,k]>0 then if a[k,j]>0 then          if a[i,j]<a[i,k]+a[k,j] then a[i,j]:=a[i,k]+a[k,j];  for i:=1 to n do    for j:=1 to n do      if a[i,j]>max then max:=a[i,j];  writeln(max);end.

0 0