0
$\begingroup$

Considering that there no cycles in the graph.

I have seen the posts where the negation of the weights is suggested and to use Bellman-ford. But I was wondering if the inverse is possible.

$\endgroup$
  • 3
    $\begingroup$ Have you tried working through a few examples by hand? I think you should be able to work out the answer on your own. $\endgroup$ – D.W. May 2 '17 at 7:52
  • 3
    $\begingroup$ Hint: $1/a + 1/b \neq 1/(a+b)$. $\endgroup$ – Yuval Filmus May 2 '17 at 9:40
3
$\begingroup$

Hint: take a graph with all weights equal 1.

$\endgroup$
3
$\begingroup$

Yes, this works for undirected acyclic graphs. Such a graph is a forest so there is exactly one path between two vertices in the same component. Since there is exactly one path, the shortest path is also the longest path, regardless of what weights you use.

For directed acyclic graphs, it fails for the reason that Eugene points out.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.