Given N, a connection cap, and a power cap, construct a two-stage router graph with collectors and distributors that satisfies all correctness conditions.
Medium5GraphImplementationMathNo attempts yetTime limit2sMemory limit512 MBA router is built from nodes and one way connections between pairs of distinct nodes:
Node X can send data to node Y if X=Y, or if there is a node Z such that X can send data to Z and a connection runs from Z to Y. When X=Y and X can send data to Y, a data path from X to Y is a set of connections {(A1,A2),(A2,A3),…,(AL−1,AL)} with L≥2, A1=X and AL=Y.
The router works properly when all of these hold:
The power of 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 of the router is Pmax=max(P1,P2,…,P2N+K).
You are given N, Mlim and Plim. Build the router described in the output section. That router works properly, uses at most Mlim connections, keeps Pmax at most Plim, and uses at most 500000 nodes in total.
One line with three integers N, Mlim and Plim, separated by spaces (1≤N≤5000, N≤Plim≤109, 1≤Mlim≤500000).
The router described in the output section uses at most Mlim connections.
Let s=min(N,⌊Plim/N⌋) and g=⌈N/s⌉. Build the router this way.
On the first line print the total number of nodes Ntot=2N+2g and the number of connections M=2N+g2, separated by a space. On each of the next M lines print two integers X and Y, meaning a connection from node X to node Y. Sort the connections by X in increasing order, and by Y in increasing order when X is equal.