Router 2
Time limit2sMemory limit512 MB
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.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Implementation, Combinatorics
- Solved
- No attempts yet
Problem
Henry and Hetty were hired by a networking company. Their first project is a new router, the Connect Ethernet Operating Interface 2016, built from:
- input nodes, numbered from to ;
- output nodes, numbered from to ;
- internal nodes, numbered from to ;
- unidirectional direct connections between pairs of distinct nodes.
A node can send data to a node (equivalently, can receive data from ) if one of the following holds:
- ;
- there is a node such that can send data to and a direct connection runs from to .
If and can send data to , a data path from to is a set of direct connections for some with and .
A router works properly if all of the following hold:
- every input node can send data to every output node;
- every input node receives data only from itself;
- every output node sends data only to itself;
- if and can send data to , then cannot send data to ;
- if and can send data to , the data path from to is unique. In particular, at most one direct connection joins any two nodes.
The power needed to operate a node is , where is the number of input nodes that can send data to and is the number of output nodes that can receive data from . The maximum power used by the router is .
Build a router that satisfies all of the following:
- it has exactly input nodes and exactly output nodes;
- it uses at most direct connections;
- its maximum power is at most ;
- it uses at most nodes in total, that is .
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.
Input
The first and only line contains three integers , and , separated by spaces. is the number of input nodes and also the number of output nodes, is the largest number of direct connections allowed, and is the largest power the router may use.
, , . The input always satisfies and .
Output
On the first line print the total number of nodes and the number of direct connections , separated by a space. On each of the next lines print one direct connection as a pair , meaning a direct connection runs from node to node . Print the connections sorted by increasing , and by increasing when ties.
Read the whole output as the integer sequence . Among the outputs of all routers that meet the requirements, print the lexicographically smallest such sequence.