CSES - Planets

The game has nn planets numbered 1,2,,n1,2,\dots,n. A player starts at the planet 11 and wins the game by reaching the planet nn.

The planets are connected by teleports. Each teleport is described by a pair (a,b)(a,b), where a<ba<b, and teleports a player from the planet aa to the planet bb.

You have successfully played the game through, but you want to prevent anyone else from winning the game. How many teleports do you need to remove from the game?

In a file planets.py, implement the class Planets with the following methods:

  • add_teleport adds a teleport from the planet aa to the planet bb
  • min_removals returns the minimum number of teleports to remove
class Planets:
    def __init__(self, n):
        # TODO

    def add_teleport(self, a, b):
        # TODO

    def min_removals(self):
        # TODO

if __name__ == "__main__":
    planets = Planets(5)

    print(planets.min_removals()) # 0

    planets.add_teleport(1, 2)
    planets.add_teleport(2, 5)
    print(planets.min_removals()) # 1

    planets.add_teleport(1, 5)
    print(planets.min_removals()) # 2