algorithm - Shortest path in a dag but must go through m type-A edges and n type-B edges -


there dag (directed acyclic graph) weight on each edge, , each edge has type, either type-a or type-b

for example:

imgur

(red edges mean type-a, , black edges mean type-b edges)

the problem defined following:

given 2 vertices s, t, find shortest path between these 2 vertices subject usage of m type-a edges , n type-b edges, or report no such path exists 

e.g., given a, d , m = 1, n = 2, find shortest path between , d , meanwhile meet constraint

in case, shortest path a, b, c, d , shortest path length 7

one idea had popped on head, first, topological sort, using topological order examination sequence, keep tracking shortest path length , traversed edges starting a

the bookkeeping record this,

[number_of_type_a, number_of_type_b, shortest_length, predecessor]

and keep considering incoming edge usual way find shortest path in dag

e.g.

imgur

(i missed 3 on edge (b,d) )

consider a:

[0, 0, 0, nil] 

consider b: (1 incoming edge)

[1, 0, 1, a] 

consider c: (2 incoming edge)

[1, 1, 3, b] ,  [1, 0, 1, a] 

consider d: (2 incoming edge)

[1, 2, 7, c] , [1, 1, 5, c] ,  [2, 0, 4, b] 

since there path using 1 type-a , 2 type-b edges, , shortest path , length can found on record , tracking predecessors

so it.

( time complexity is...o(v+e)? think maybe bigger this, have no idea how analyse it)

i not sure right way solve problem.

is there other way solve problem? , problem called in general?

thanks help!


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -