#P14801. [CCPC 2024 哈尔滨站] 造计算机

[CCPC 2024 哈尔滨站] 造计算机

Description

You want to build a computer to achieve a specific functionality: Given an integer xx, determine whether xx lies within the interval [L,R][L, R]. To accomplish this, you designed a directed acyclic graph (DAG) with edge weights of 00 and 11, which contains a starting node with an indegree of 00 and an ending node with an outdegree of 00. 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 [L,R][L, R] without leading zeros. Every integer within the range [L,R][L, R] must correspond to exactly one unique path in this graph. In this way, you can determine whether an integer lies within the range [L,R][L, R] 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 100100 nodes, where each node has an outdegree of at most 200200. The DAG must have edge weights of 00 and 11, with exactly one starting node with an in-degree of 00 and one ending node with an out-degree of 00. Every integer in the range [L,R][L, R] must correspond to exactly\textbf{exactly} one unique path from the start to the end in this DAG, and no path should represent any integer outside the range [L,R][L, R]. 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 L,RL, R (1LR1061 \le L \le R \le 10^6).

Output Format

The first line should output the number of nodes nn (1n1001 \le n \le 100).

For the next nn lines, the ii-th line should start with an integer kk (0k2000 \le k \le 200), representing the number of outgoing edges from node ii. Then output 2k2 \cdot k integers ai,k,vi,ka_{i,k}, v_{i,k} (1ai,kn1 \le a_{i,k} \le n, ai,kia_{i,k} \neq i, vi,k{0,1}v_{i,k} \in \{0, 1\}), which means that node ii has a directed edge with weight vi,kv_{i,k} to node ai,ka_{i,k}. 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