Bitland has n airports, initially with no connecting flights. Your task is to implement a class that supports adding a one-directional flight connection between two airports and checking if every airport is reachable from all other airports (possibly with changes at other airports).
You may assume that there is at most 50 airports and that the methods are called at most 100 times.
In a file airports.py
, implement a class Airports
with the following methods:
- constructor with the number of airports as a parameter
add_link
adds a connection from the airport a to the airport bcheck
find out if every airport is reachable from all other airports.
class Airports: def __init__(self,n): # TODO def add_link(self,a,b): # TODO def check(self): # TODO if __name__ == "__main__": a = Airports(5) a.add_link(1,2) a.add_link(2,3) a.add_link(1,3) a.add_link(4,5) print(a.check()) # False a.add_link(3,5) a.add_link(1,4) print(a.check()) # False a.add_link(5,1) print(a.check()) # True