Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,
im a little rusty on my algorithms so maybe you can help me.
given an undirected graph (V,E) and a number K and suppose some of the vertices are 'red' and the others are 'blue'.
how can i find a path with length <= K from s to t that passes the most red vertices?

thanks

What I have tried:

i tried looking for a path with length 1, than 2, ... till K but it still doesnt go through the maximal amount of red vertices.
Posted
Updated 26-May-16 15:24pm
v2
Comments
Sergey Alexandrovich Kryukov 25-May-16 11:34am    
It looks like the only solution is brute force: find all paths and calculate number of red vertices for each, find the one with maximum red vertices.
—SA
Patrice T 25-May-16 15:26pm    
What have you done already ?
Post your code.
Use Improve question to update your question.
So that everyone can pay attention to this information.

1 solution

Quote:
how can i find a path with length <= K from s to t that passes the most red vertices?
The solution is brut force.
You have to try all possible path one by one and save the best answer so far.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900