Under construction

Still being built. Things may change

Router 7

Time limit2sMemory limit512 MB

Summary
Build a router graph with N inputs, N outputs, and internal nodes so each input reaches each output by a unique path within edge and power limits.
Level

Hard8 of 10

Topics
Graph, Tree, Implementation
Solved
No attempts yet

Problem

Henry and Hetty were recently hired by a networking company from Piatra Neamț. Their first project is to build a new router, the Connect Ethernet Operating Interface 2016, which has the following parts:

  • NN input nodes, numbered 1 to NN.
  • NN output nodes, numbered N+1N+1 to 2×N2 \times N.
  • KK internal nodes, numbered 2×N+12 \times N+1 to 2×N+K2 \times N+K.
  • MM unidirectional direct connections between pairs of distinct nodes.

Node XX can send data to node YY if X=YX = Y, or if some node ZZ exists such that XX can send data to ZZ and there is a direct connection from ZZ to YY.

If XX can send data to YY and X≠YX \neq Y, the data path from XX to YY is a set of direct connections {(A1,A2),(A2,A3),…,(AL−1,AL)}\{(A_1, A_2), (A_2, A_3), \ldots, (A_{L-1}, A_L)\} for some L≥2L \ge 2, with A1=XA_1 = X and AL=YA_L = Y.

A router works properly if:

  • Each input node can send data to each output node.
  • Each input node can receive data only from itself.
  • Each output node can send data only to itself.
  • For any two nodes X≠YX \neq Y, if XX can send data to YY, then YY cannot send data to XX.
  • For any two nodes X≠YX \neq Y, if XX can send data to YY, the data path from XX to YY is unique. In particular, any two nodes are connected by at most one direct connection.

The power needed to operate node XX is PX=INX×OUTXP_X = IN_X \times OUT_X, where INXIN_X is the number of input nodes that can send data to XX, and OUTXOUT_X is the number of output nodes that can receive data from XX. The maximum power used by the router is Pmax=max⁡(P1,P2,…,P2×N+K)P_{max} = \max(P_1, P_2, \ldots, P_{2 \times N+K}).

For the given specification, build a router that:

  • has exactly NN input nodes and NN output nodes;
  • uses at most MlimM_{lim} direct connections;
  • uses maximum power at most PlimP_{lim};
  • uses at most 500000 nodes in total (Ntot=2×N+K≤500000N_{tot} = 2 \times N + K \le 500000).

Input

The first and only line contains three integers: NN, the number of input and output nodes, MlimM_{lim}, the maximum number of direct connections, and PlimP_{lim}, the maximum power used by the router.

For this test, N=9978N = 9978, Mlim=100000M_{lim} = 100000, and Plim=100000P_{lim} = 100000.

Output

Print Ntot=2×N+KN_{tot} = 2 \times N + K and MM on the first line, separated by a space. Then print MM lines, each containing two integers XX and YY, which means a direct connection from node XX to node YY is built.

Examples1

  1. Example 1

    Input
    3 100 200
    
    Expected output
    9 8
    1 7
    2 7
    3 8
    7 8
    8 4
    8 9
    9 5
    9 6