#P2196. [NOIP 1996 提高组] 挖地雷
[NOIP 1996 提高组] 挖地雷
Description
On a map there are () cellars, each containing a certain number of mines. The connections between cellars are given. After the data of the cellars and their connections are provided, a person can start digging mines from any cellar. Each time, they may move to a connected cellar whose index is strictly larger than the current node’s index to dig mines. The digging ends when there is no node that satisfies the condition. Design a digging plan so that the person can collect the maximum number of mines.
Input Format
Multiple lines.
The first line contains a single integer, the number of cellars .
The second line contains integers, representing the number of mines in each cellar.
Lines to describe the connections between cellars:
- Line has numbers ( or ), indicating whether there is a path from the first cellar to the -nd, -rd, …, -th cellar. For example, if line is , it means there is a path from cellar to cellar , a path from cellar to cellar , and no path from cellar to cellar , cellar , …, cellar .
- Line has numbers, indicating whether there is a path from the second cellar to the -rd, -th, …, -th cellar.
- …
- Line has number, indicating whether there is a path from the -th cellar to the -th cellar (where means no path and means there is a path).
Output Format
The first line prints the digging order when the maximum number of mines is collected. The indices of the cellars are separated by a single space, with no extra spaces.
The second line contains a single integer, the maximum number of mines that can be collected.
5
10 8 4 7 6
1 1 1 0
0 0 0
1 1
1
1 3 4 5
27
Hint
[Sample Explanation]
The optimal path is , and the result is .
[Source] NOIP 1996 Senior, Problem 3.
Translated by ChatGPT 5
京公网安备 11011102002149号