Router 7
Time limit2sMemory limit512 MB
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:
- input nodes, numbered 1 to .
- output nodes, numbered to .
- internal nodes, numbered to .
- unidirectional direct connections between pairs of distinct nodes.
Node can send data to node if , or if some node exists such that can send data to and there is a direct connection from to .
If can send data to and , the data path from to is a set of direct connections for some , with and .
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 , if can send data to , then cannot send data to .
- For any two nodes , if can send data to , the data path from to is unique. In particular, any two nodes are connected by at most one direct connection.
The power needed to operate 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 .
For the given specification, build a router that:
- has exactly input nodes and output nodes;
- uses at most direct connections;
- uses maximum power at most ;
- uses at most 500000 nodes in total ().
Input
The first and only line contains three integers: , the number of input and output nodes, , the maximum number of direct connections, and , the maximum power used by the router.
For this test, , , and .
Output
Print and on the first line, separated by a space. Then print lines, each containing two integers and , which means a direct connection from node to node is built.