16/40
Part 4 of 7 · A park with no cyclesLearn
A downhill park is a graph with no cycles
Now the practice problem's bike park. There are one-way stretches of trail between junctions, each worth a score that can be negative. There is a trailhead at the top, and several exits where a ride may end. Here is a small park:
PARK = [
("top", "birch", 2),
("top", "ash", 3),
("ash", "cliff", 4),
("birch", "cliff", 4),
("birch", "dell", 6),
("cliff", "falls", 5),
("cliff", "end", 1),
("dell", "end", 2),
]
EXITS = ["end", "falls"]
junctions = {j for upper, lower, _ in PARK for j in (upper, lower)}
print(len(PARK), "stretches between", len(junctions), "junctions")
8 stretches between 7 junctions
What's the best total of a route from top to an exit?
Pick an answer above to see the rest