3 / 3
Jun 2012

Hi,
could you please help me with this problem (it is not contest-related problem):
I have got a weight undirect graph and a list of vertices I have to visit
I want to find shortest path (from source vertex to destination vertex) with no cycles, I have to visit each vertex exactly once (also order of vertices is important - it must be the same order is given in input) and I cannot use one edge twice

my current solution is pretty brute-force:
first I find all possible paths between two given vertices using Breadth-first search ; after that I calculate how long is each path and sort these paths from shortest to longest
the next step is to iterate through all paths (begining with the shortest one) and check if I have visited all given vertices and in correct order

instead of BFS I was also thinking about Floyd–Warshall algorithm, but I don't think I can find all paths between two vertices using Floyd-Warshall

could you pls help me how to solve this? (because my solution is .... well...)
I don't really care about time complexity - there will be max 10 vertices and not too much edges, so no big deal

thanks a lot

  • created

    Feb '12
  • last reply

    Jun '12
  • 2

    replies

  • 314

    views

  • 3

    users

Define "not too much edges". Can you define a maximum? Is there guaranteed to be a solution? Sample input? Expected output?

You do realize that you say in the same post that you are not worried about complexity but that you don't like your solution because of complexity.

Given that the constraints on nodes is so low, I'm expecting a BFS state of {current city, cities visited, next city in path} for a maximum state size of 10*10*2^10.

4 months later

I am new here and read your all post. I think it is not a big problem and i think you must get the soluation from the others experienced member.I am totally new and looking for some good forum. So please warned be before banned if i did any mistake.

Suggested Topics

Topic Category Replies Views Activity
Off-topic 1 129 Apr 9

Want to read more? Browse other topics in Off-topic or view latest topics.