CSES - Planets

The game has n planets numbered 1,\dots,n. A Player starts at the planet 1 and wins the game by reaching the planet n.

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

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?

You may assume that n is at most 50 and that the methods of the class are called at most 100 times.

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

  • constructor with n as a parameter
  • add_teleport adds a teleport from a planet a to a planet b
  • calculate returns the minimum number of teleports to remove
class Planets:
    def __init__(self,n):
        # TODO

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

    def calculate(self):
        # TODO

if __name__ == "__main__":
    p = Planets(5)
    print(p.calculate()) # 0
    p.add_teleport(1,2)
    p.add_teleport(2,5)
    print(p.calculate()) # 1
    p.add_teleport(1,5)
    print(p.calculate()) # 2