#P14801. [CCPC 2024 哈尔滨站] 造计算机
[CCPC 2024 哈尔滨站] 造计算机
Description
You want to build a computer to achieve a specific functionality: Given an integer , determine whether lies within the interval . To accomplish this, you designed a directed acyclic graph (DAG) with edge weights of and , which contains a starting node with an indegree of and an ending node with an outdegree of . By starting from the starting node and following a path to the ending node, the sequence of the traversed edge weights forms a binary representation of an integer within the range without leading zeros. Every integer within the range must correspond to exactly one unique path in this graph. In this way, you can determine whether an integer lies within the range by checking if its binary representation can be constructed by traversing this DAG.
Clearly, you could separate the corresponding path for each integer into individual chains. However, you realized that for a large range, such a DAG would require too many nodes, and the computer you built with only 256 MiB of memory cannot store it. Therefore, you need to compress this DAG, allowing different paths to share nodes, in order to reduce the number of nodes and edges. Formally, you need to construct a DAG with no more than nodes, where each node has an outdegree of at most . The DAG must have edge weights of and , with exactly one starting node with an in-degree of and one ending node with an out-degree of . Every integer in the range must correspond to one unique path from the start to the end in this DAG, and no path should represent any integer outside the range . Note that none of the binary sequences formed by any path in the graph should have leading zeros. There may be two edges with different weights between two nodes.
Input Format
A single line containing two positive integers ().
Output Format
The first line should output the number of nodes ().
For the next lines, the -th line should start with an integer (), representing the number of outgoing edges from node . Then output integers (, , ), which means that node has a directed edge with weight to node . You must ensure that the output represents a directed acyclic graph that satisfies the requirements.
5 7
8
3 2 1 3 1 4 1
1 5 0
1 6 1
1 7 1
1 8 1
1 8 0
1 8 1
0
京公网安备 11011102002149号