#P4294. [WC2008] 游览计划
[WC2008] 游览计划
Description
Little D, who has never been to Shaoxing, was lucky to attend Winter Camp 2008. He was captivated by the beautiful scenery of this historic city and strongly requested to visit all scenic spots in and around Shaoxing.
The organizers divide Shaoxing into rows and columns, i.e., an grid, as in the figure ():

Each scenic spot lies within a cell, and each cell contains at most one scenic spot. A cell without a scenic spot is considered a road.
For safety and convenience, based on road and security conditions, the organizers place different numbers of volunteers in some non-scenic cells; in scenic cells they hire tour guides (guides are not volunteers). When choosing a touring plan, we must ensure that between any two scenic spots there exists a path such that every cell on this path either has volunteers or is itself a scenic spot. The plan should meet contestants’ touring needs while minimizing the total number of volunteers.
For example, in the example above, each non-scenic cell is assigned a number indicating the minimum number of volunteers needed to control that cell:

The dark-shaded region shows one feasible volunteer arrangement, requiring a total of volunteers. As can be seen, two adjacent scenic spots are directly connected (via roads inside the scenic spots), e.g., 沈园 and 八字桥.
Now, please help the organizers find the best arrangement.
Input Format
The first line contains two integers, and , describing the number of cells.
The next lines each contain nonnegative integers. If an integer is , then the corresponding cell is a scenic spot; otherwise, it is the minimum number of volunteers required to control that cell. Adjacent integers are separated by one or more spaces; there may also be extra spaces at the beginning or end of a line.
Output Format
Output lines. The first line is a single integer, the total number of volunteers in your plan.
Then output lines, each containing characters, describing the status of each cell in your plan:
_(underscore) means no volunteers are placed in that cell.o(lowercase letter o) means volunteers are placed in that cell.x(lowercase letter x) means that cell is a scenic spot.
Note: Please strictly follow the output format. If any line is missing, or if any line contains an incorrect number of characters (and no extra spaces are allowed on any line), that test point may receive no score.
4 4
0 1 1 0
2 5 5 1
1 5 5 1
0 1 1 0
6
xoox
___o
___o
xoox
Hint
Constraints (across all groups of testdata) on , , and the number of scenic spots are as follows:
| Test case ID | |||
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 | |||
| 8 | |||
| 9 | |||
| 10 | |||

All integers in the input file are between and , inclusive.
Translated by ChatGPT 5
京公网安备 11011102002149号