Paths in graphs

3.7

29 votes
Graphs, Algorithms, Graph Representation
Problem

You are given positive integer k. Find a graph G that satisfies all of the following conditions:

  • G consists of n nodes and m edges
  • G is a directed acyclic graph
  • 2n300, 1m400
  • Number of simple paths from vertex 1 to vertex n is equal to k

Input format

  • The single line contains one number k (1k1018).

 Output format

  • The first line contains two numbers n and m.
  • Next m lines contain two numbers u and v that means there are directed edge from u to v. (1uvn).

Please note that the sample is not the first test 

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

There are 3 simple paths:

  • 1 -> 2 -> 4
  • 1 -> 3 -> 4
  • 1 -> 4
Editor Image

?