CSES - Paths

Your task is to construct a directed acyclic graph with 100100 nodes and exactly xx different paths from the node 11 to the node 100100. The graph can have at most 10001000 edges and every edge must be different.

For example, when x=5x=5, one possible solution consists of the edges (1,3),(1,5),(2,100),(3,2),(3,100),(5,2),(5,3).(1,3),(1,5),(2,100),(3,2),(3,100),(5,2),(5,3). In this case, the paths are:

  • 131001 \rightarrow 3 \rightarrow 100
  • 1321001 \rightarrow 3 \rightarrow 2 \rightarrow 100
  • 1521001 \rightarrow 5 \rightarrow 2 \rightarrow 100
  • 1531001 \rightarrow 5 \rightarrow 3 \rightarrow 100
  • 15321001 \rightarrow 5 \rightarrow 3 \rightarrow 2 \rightarrow 100

You may assume that xx is an integer in the range 11091 \dots 10^9. You can construct any graph that satisfies the conditions.

In a file paths.py, implement a function create that returns the graph as a list of edges.

def create(x):
    #TODO

if __name__ == "__main__":
    print(create(2)) # esim. [(1,2), (1,100), (2,100)]
    print(create(5))
    print(create(10))
    print(create(123456789))