Build a unique-path layered router digraph with N inputs and N outputs, at most M_lim edges, node power at most P_lim, printing the lexicographically smallest edge list.
Hard8GraphGreedyImplementationCombinatoricsNo attempts yetTime limit2sMemory limit512 MBHenry and Hetty were hired by a networking company. Their first project is a new router, the Connect Ethernet Operating Interface 2016, built from:
A node X can send data to a node Y (equivalently, Y can receive data from X) if one of the following holds:
If X=Y and X can send data to Y, a data path from X to Y is a set of direct connections {(A1,A2),(A2,A3),…,(AL−1,AL)} for some L≥2 with A1=X and AL=Y.
A router works properly if all of the following hold:
The power needed to operate a node X is PX=INX×OUTX, where INX is the number of input nodes that can send data to X and OUTX is the number of output nodes that can receive data from X. The maximum power used by the router is Pmax=max(P1,P2,…,P2N+K).
Build a router that satisfies all of the following:
Several routers meet these requirements, so only one of them counts as correct: the lexicographically smallest one under the rule given in the output format.
The first and only line contains three integers N, Mlim and Plim, separated by spaces. N is the number of input nodes and also the number of output nodes, Mlim is the largest number of direct connections allowed, and Plim is the largest power the router may use.
1≤N≤250, 1≤Mlim≤1000000, 1≤Plim≤1000000. The input always satisfies N2≤Mlim and N≤Plim.
On the first line print the total number of nodes Ntot=2N+K and the number of direct connections M, separated by a space. On each of the next M lines print one direct connection as a pair X Y, meaning a direct connection runs from node X to node Y. Print the connections sorted by increasing X, and by increasing Y when X ties.
Read the whole output as the integer sequence Ntot,M,X1,Y1,…,XM,YM. Among the outputs of all routers that meet the requirements, print the lexicographically smallest such sequence.