Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following (directed, edge-weighted) graph problem. In a set of n vertices, G, there is a source vertex, s. I need to compute the shortest path between s and every other vertex.

I can't use Dijkstra directly since edge distances can be negative. The graph also has cycles. I realize that one can go round and round to make the total distance as low as one wants. However, I would like to find the shortest path (in terms of edge weight sums) from s to a given node, such that the path does not have any cycles.

Am I thinking about this the wrong way?

share|cite|improve this question

I'm not sure, but this seems to be NP-hard. Here is why.

Suppose you have an algorithm to find the simple path (i.e. path without cycles) with minimal weight between any two nodes. Using this algorithm, you can make an algorithm for finding the longest (in terms of number of edges) simple path between any two nodes simply by assigning weight $-1$ to all edges. And you can use this second algorithm to solve the Hamiltonian path problem, which is NP-complete.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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