#P5441. 【XR-2】伤痕
【XR-2】伤痕
Description
Country X has suffered an unprecedented earthquake. People are covered in scars, and the whole country is shattered.
To help people heal, and also to allow Country X to survive, the King of Country X decides to rebuild the country.
The King decides to first build cities. Since the King likes odd numbers, is odd.
After the cities are built, a road must be built between every pair of cities, i.e., a total of roads.
However, the cost of building bidirectional roads is too high. After building cities, the remaining budget is enough to build at most bidirectional roads, and all other roads can only be built as one-way roads. Fortunately, the direction does not affect the cost of building a one-way road, so the directions of all one-way roads can be chosen arbitrarily.
In addition, after the rebuilding is completed, the King will designate cities as the core cities of Country X. To promote the development of Country X, for any two of these core cities, they must be able to reach each other without passing through non-core cities.
The King hopes that you can provide him with a road construction plan such that, after the rebuilding is completed, the number of ways to choose core cities is maximized.
Input Format
One line containing a positive integer , guaranteed that is odd, meaning there are cities.
Output Format
The first line contains an integer, representing the maximum number of ways to choose core cities.
The next lines each contain positive integers describing an adjacency matrix, representing your road construction plan.
Specifically, the -th number in the -th line is if city can reach city via a road, and if city cannot reach city via a road. We explain in detail in cases:
- If the road between and is a one-way road from to , then the number in row , column of the adjacency matrix is , and the number in row , column is .
- If the road between and is a bidirectional road, then both the number in row , column and the number in row , column are . You must ensure that at most bidirectional roads are built.
- If , then the number in row , column (the number in row , column ) is .
3
0
0 1 1
0 0 1
0 1 0
5
5
0 1 0 1 1
0 0 1 1 0
1 0 0 0 1
1 0 1 0 1
1 1 0 0 0
Hint
[Sample Explanation]
Since there are only points in total, the number of ways to choose core cities must be . So you only need to ensure that the construction plan satisfies the requirements.
[Sample Explanation]

Obviously, among points, choosing any points satisfies the core-city condition, so the maximum number of ways is .
[Constraints]
This problem has test points, each worth points. For the -th test point, .
For each test point, there are five possible outcomes:
- Output format error, including: not outputting the maximum number of ways, not outputting the adjacency matrix, outputting extra information, etc. You will not get any points for this test point, and we cannot determine the return result of the Special Judge.
- The maximum number of ways is not computed correctly, even if the constructed road plan is correct. You will get of the score for this test point (i.e., points). The Special Judge will return WA and output “The answer is wrong.”
- The maximum number of ways is computed correctly, but the constructed road plan does not satisfy the requirements, including: numbers in the adjacency matrix that are not or , self-loops, a pair of cities with no road between them, more than bidirectional roads, etc. You will get of the score for this test point (i.e., point). The Special Judge will return WA and output “The answer is correct, but your plan breaks the rules.”
- The maximum number of ways is computed correctly, and the constructed road plan satisfies the requirements, but the number of ways to choose core cities is not maximized. You will get of the score for this test point (i.e., point). The Special Judge will return WA and output “The answer is correct, but your plan is wrong.”
- The maximum number of ways is computed correctly, and the road construction plan is also constructed correctly. You will get of the score for this test point (i.e., points). The Special Judge will return AC and output “The answer is correct.”
Translated by ChatGPT 5
京公网安备 11011102002149号