Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

MarioYC's blog

By MarioYC, 14 years ago, In English

As the title says, in a graph where the distance of going between two nodes is the concatenation of the strings in the edges along the path between this two verticesm, and we want to find the lexicographically shortest distance, what distance function and which algorithm can we use to solve this kind of problems?

I was trying to solve this problem, and implement a code which uses the Floyd-Warshall algorithm, but there is a problem with cases like this:

V = 3, E = 3, s = 0, e = 2 0 -> 1 a 0 -> 1 ab 1 -> 2 c

The code returns "ac", but the right answear is "abc".

  • Vote: I like it
  • +5
  • Vote: I do not like it

| Write comment?
»
14 years ago, hide # |
Rev. 3  
Vote: I like it +5 Vote: I do not like it

1) For each node you can determine, if "gold node" is reachable from it. You can do it with 1 bfs with reversed edges from "gold node"
2) Start from start node, always select smallest lexicographically edge leading to a vertex from which the “gold node” is reachable. (Thx for Endagorion) 3) If you find cycle, it's "NO".