Print either a star-shaped router with one internal hub or a fully connected bipartite router, depending on whether N*N exceeds P_lim.
Easy3GraphImplementationSimulationNo 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, 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 can send data to Y and X=Y, the data path from X to Y is the set of direct connections {(A1,A2),(A2,A3),…,(AL−1,AL)} with L≥2, A1=X and AL=Y.
A router works properly when all of the following hold:
The power needed to operate 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. Writing Ntot=2N+K for the total number of nodes, the maximum power used by the router is Pmax=max(P1,P2,…,PNtot).
You are given N, Mlim and Plim. Build a router that works properly, has exactly N input nodes and N output nodes, uses at most Mlim direct connections, has Pmax≤Plim, and uses at most 500000 nodes in total. Several routers meet such a specification, so the output section fixes the single one you must print.
One line with three integers N, Mlim and Plim: the number of input nodes and of output nodes, the largest number of direct connections allowed, and the largest power the router may use (1≤N≤1000, 1≤Mlim≤106, 1≤Plim≤106).
It is guaranteed that N≤Plim and that the router described in the output section uses at most Mlim direct connections.
Print the router picked by the rule below.
If N×N≤Plim, print the router with one internal node. It has Ntot=2N+1 nodes and M=2N direct connections: first the connections i→2N+1 for i=1,2,…,N in increasing order of i, then the connections 2N+1→N+j for j=1,2,…,N in increasing order of j.
Otherwise print the router with no internal node. It has Ntot=2N nodes and M=N×N direct connections, namely i→N+j for every pair (i,j), sorted by i increasing and, for equal i, by j increasing.
The first line holds Ntot and M separated by a space. Each of the next M lines holds two integers X and Y, meaning a direct connection from node X to node Y was built.