A14645 | Defender of Childhood Dreams
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Even if you just leave them be, they will fall to pieces all by themselves. So, someone has to protect them, right?
You find yourself playing with Teucer again in the city of Liyue. As you take the eccentric little kid around, you notice something interesting about the structure of the city.
Liyue can be represented as a directed graph containing $n$ nodes. Nodes are labeled from $1$ to $n$ . There is a directed edge from node $a$ to node $b$ if and only if $a < b$ .
A path between nodes $a$ and $b$ is defined as a sequence of edges such that you can start at $a$ , travel along all of these edges in the corresponding direction, and end at $b$ . The length of a path is defined by the number of edges. A rainbow path of length $x$ is defined as a path in the graph such that there exists at least 2 distinct colors among the set of $x$ edges.
Teucer's favorite number is $k$ . You are curious about the following scenario: If you were to label each edge with a color, what is the minimum number of colors needed to ensure that all paths of length $k$ or longer are rainbow paths?
Teucer wants to surprise his older brother with a map of Liyue. He also wants to know a valid coloring of edges that uses the minimum number of colors. Please help him with this task!
You find yourself playing with Teucer again in the city of Liyue. As you take the eccentric little kid around, you notice something interesting about the structure of the city.
Liyue can be represented as a directed graph containing $n$ nodes. Nodes are labeled from $1$ to $n$ . There is a directed edge from node $a$ to node $b$ if and only if $a < b$ .
A path between nodes $a$ and $b$ is defined as a sequence of edges such that you can start at $a$ , travel along all of these edges in the corresponding direction, and end at $b$ . The length of a path is defined by the number of edges. A rainbow path of length $x$ is defined as a path in the graph such that there exists at least 2 distinct colors among the set of $x$ edges.
Teucer's favorite number is $k$ . You are curious about the following scenario: If you were to label each edge with a color, what is the minimum number of colors needed to ensure that all paths of length $k$ or longer are rainbow paths?
Teucer wants to surprise his older brother with a map of Liyue. He also wants to know a valid coloring of edges that uses the minimum number of colors. Please help him with this task!
输入格式
The only line of input contains two integers $n$ and $k$ ( $2 \leq k < n \leq 1000$ ).
输出格式
On the first line, output $c$ , the minimum colors you need to satisfy the above requirements.
On the second line, print a valid edge coloring as an array of $\frac{n(n-1)}{2}$ integers ranging from $1$ to $c$ . Exactly $c$ distinct colors should exist in the construction. Print the edges in increasing order by the start node first, then by the second node.
For example, if $n=4$ , the edge colors will correspond to this order of edges: ( $1$ , $2$ ), ( $1$ , $3$ ), ( $1$ , $4$ ), ( $2$ , $3$ ), ( $2$ , $4$ ), ( $3$ , $4$ )
On the second line, print a valid edge coloring as an array of $\frac{n(n-1)}{2}$ integers ranging from $1$ to $c$ . Exactly $c$ distinct colors should exist in the construction. Print the edges in increasing order by the start node first, then by the second node.
For example, if $n=4$ , the edge colors will correspond to this order of edges: ( $1$ , $2$ ), ( $1$ , $3$ ), ( $1$ , $4$ ), ( $2$ , $3$ ), ( $2$ , $4$ ), ( $3$ , $4$ )
输入输出样例
输入 #1
5 3
输出 #1
2 1 2 2 2 2 2 2 1 1 1
输入 #2
5 2
输出 #2
3 3 2 2 1 2 2 1 3 1 1
输入 #3
8 7
输出 #3
2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
输入 #4
3 2
输出 #4
2 1 2 2
The corresponding construction for the first test case looks like this:
 It is impossible to satisfy the constraints with less than $2$ colors.The corresponding construction for the second test case looks like this:
 One can show there exists no construction using less than $3$ colors.
 It is impossible to satisfy the constraints with less than $2$ colors.The corresponding construction for the second test case looks like this:
 One can show there exists no construction using less than $3$ colors.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted