#P5419. [CTSC2016] 单调上升序列

    ID: 4356 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016WC/CTSC/集训队Special JudgeO2优化

[CTSC2016] 单调上升序列

Description

For a weighted undirected graph, we can study its monotonically increasing paths.

A path is called monotonically increasing if, when you traverse it, the edge weights are monotonically increasing.

Note that a path consists of multiple edges connected end to end, and it may pass through the same vertex multiple times. The length of a path is the number of edges it contains.

For example, in the figure below, $v_2 \rightarrow v_4 \rightarrow v_1 \rightarrow v_2$ is a monotonically increasing path, because the weights of its edges are 1,2,41,2,4. The length of this path is 33. Furthermore, you can verify that in the figure below, the length of every monotonically increasing path is at most 33.

Example

The following statement shows that in some graphs, there will always be a relatively long monotonically increasing path:

Statement: Suppose a weighted undirected graph GG has 100100 vertices and 10001000 edges, and all edge weights are pairwise distinct. Then there must exist a monotonically increasing path in GG whose length is at least 2020.

Proof: Suppose there is an explorer on each vertex. We enumerate all edges in increasing order of weight, and each time we swap the positions of the explorers on the two endpoints of the current edge. It can be seen that each explorer walks along a monotonically increasing path. Also, since there are 100100 explorers and the explorers walk a total of 20002000 steps, someone must have walked 2020 steps. QED.

Now, our problem is:

You are given a complete graph GG whose number of vertices is an even number NN.

Your task is to assign a distinct weight to each edge so that the length of the longest monotonically increasing path is as small as possible.

Input Format

The input contains only one line with a positive even integer NN.

Output Format

Output a permutation of the integers 11 to N(N1)2\frac{N(N-1)}{2}, with adjacent numbers separated by a single space or a newline.

The first number represents the weight you assign to edge (1,2)(1,2); the second number is the weight for (1,3)(1,3); \ldots; the NN-th number is the weight for (1,N)(1,N). Then come the weights for (2,3)(2,3), (2,4)(2,4), \ldots, (2,N)(2,N). Then the weights for (3,4)(3,4) to (3,N)(3,N), and so on. Finally, output the weight for (N1,N)(N-1,N).

4
4 6 2
3 1
5

6

12 8 15 3 5
6 7 1 13
10 14 11
4 2
9

Hint

Constraints and Notes

  • For 20%20\% of the testdata, N20N \leq 20.
  • For 50%50\% of the testdata, N100N \leq 100.
  • For 100%100\% of the testdata, 2N5002 \leq N \leq 500.

Notes

Besides different subtasks having different characteristics, you may also receive partial credit on each test. If your program can terminate correctly and output in the required format, we will score it as follows:

Suppose the length of the longest monotonically increasing path in your graph is AA, and the correct answer is BB.

  • If A=BA=B, your score is 1010 points.
  • If B<A<2BB < A < 2B, your score is 33 points.
  • If A2BA \geq 2B, your score is 00 points.

Translated by ChatGPT 5