#P1269. 信号放大器

信号放大器

Description

A tree network minimizes material use. A tree network is an acyclic connected network in which there is exactly one communication path between any two nodes.

There is one node in the network that is the server, responsible for sending a signal directly or indirectly to all terminals. As shown in the top figure, the server node sends a signal to nodes aa and cc, and aa then forwards it to bb. In this way, the entire network receives the signal.

However, in practice, when a signal is sent from one node to another, its strength attenuates. The attenuation is generally determined by the length of the line.

As shown in the bottom figure, the numbers on the edges indicate the attenuation on those edges. Suppose a signal of strength 44 units is emitted from the server; after reaching node aa, the strength attenuates to 43=14-3=1 unit. Node aa then forwards it to node bb. Since the signal strength is 11 and the attenuation is 22, the signal cannot be delivered to bb.

One way to solve this problem is to install signal amplifiers. A signal amplifier restores any signal with positive strength to the initial strength (the strength at the server when it is emitted).

In the figure above, if a signal amplifier is installed at node aa, then when the signal of strength 44 reaches aa, it is amplified back to 44. Thus, the signal can be delivered to any node in the network. To simplify the problem, we assume each node processes a signal at most once; when it receives the same signal a second time, it ignores it.

Your task is to compute, for the given tree network, the minimum number of signal amplifiers that must be installed.

Input Format

The first line contains an integer nn, the number of nodes in the network (n20000n \le 20000).

Lines 22 to n+1n+1 each describe the connections of a node. Specifically, line i+1i+1 describes node ii: it starts with an integer kk, the number of nodes adjacent to node ii. Then follow 2k2k numbers, where each pair describes a neighbor of node ii: the neighbor’s identifier (an integer between 11 and nn) and the attenuation on the edge between that neighbor and node ii. Node 11 is the server.

The last line contains one integer, the initial signal strength emitted by the server.

Output Format

Output a single integer, the minimum number of signal amplifiers required to make the signal reach the entire network.

If it is impossible to make the signal reach the entire network no matter how the amplifiers are installed, output No solution..

4
2 2 3 3 1
2 1 3 4 2
1 1 1
1 2 2
4
1

Hint

Translated by ChatGPT 5