Ticket #1700: floyd_warshall_shortest.hpp.patch

File floyd_warshall_shortest.hpp.patch, 966 bytes (added by eric80@…, 15 years ago)
  • floyd_warshall_shortest.hpp

    old new  
    5959     
    6060      for (tie(k, lastk) = vertices(g); k != lastk; k++)
    6161        for (tie(i, lasti) = vertices(g); i != lasti; i++)
    62           for (tie(j, lastj) = vertices(g); j != lastj; j++)
    63           {
    64             d[*i][*j] =
    65               detail::min_with_compare(d[*i][*j],
    66                                        combine(d[*i][*k], d[*k][*j]),
    67                                        compare);
    68           }
     62          if(d[*i][*k] != inf)
     63            for (tie(j, lastj) = vertices(g); j != lastj; j++)
     64              if(d[*k][*j] != inf)
     65                d[*i][*j] =
     66                  detail::min_with_compare(d[*i][*j],
     67                                           combine(d[*i][*k], d[*k][*j]),
     68                                           compare);
     69     
    6970     
    70    
    7171      for (tie(i, lasti) = vertices(g); i != lasti; i++)
    7272        if (compare(d[*i][*i], zero))
    7373          return false;