A10689 | PolandBall and White-Red graph
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
PolandBall has an undirected simple graph consisting of $n$ vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding some red edges. Then, he will add white edges in every remaining place. Therefore, the final graph will be a clique in two colors: white and red.
Colorfulness of the graph is a value $min(d_{r},d_{w})$ , where $d_{r}$ is the diameter of the red subgraph and $d_{w}$ is the diameter of white subgraph. The diameter of a graph is a largest value $d$ such that shortest path between some pair of vertices in it is equal to $d$ . If the graph is not connected, we consider its diameter to be -1.
PolandBall wants the final graph to be as neat as possible. He wants the final colorfulness to be equal to $k$ . Can you help him and find any graph which satisfies PolandBall's requests?
Colorfulness of the graph is a value $min(d_{r},d_{w})$ , where $d_{r}$ is the diameter of the red subgraph and $d_{w}$ is the diameter of white subgraph. The diameter of a graph is a largest value $d$ such that shortest path between some pair of vertices in it is equal to $d$ . If the graph is not connected, we consider its diameter to be -1.
PolandBall wants the final graph to be as neat as possible. He wants the final colorfulness to be equal to $k$ . Can you help him and find any graph which satisfies PolandBall's requests?
输入格式
The only one input line contains two integers $n$ and $k$ ( $2<=n<=1000$ , $1<=k<=1000$ ), representing graph's size and sought colorfulness.
输出格式
If it's impossible to find a suitable graph, print -1.
Otherwise, you can output any graph which fulfills PolandBall's requirements. First, output $m$ — the number of red edges in your graph. Then, you should output $m$ lines, each containing two integers $a_{i}$ and $b_{i}$ , ( $1<=a_{i},b_{i}<=n$ , $a_{i}≠b_{i}$ ) which means that there is an undirected red edge between vertices $a_{i}$ and $b_{i}$ . Every red edge should be printed exactly once, you can print the edges and the vertices of every edge in arbitrary order.
Remember that PolandBall's graph should remain simple, so no loops or multiple edges are allowed.
Otherwise, you can output any graph which fulfills PolandBall's requirements. First, output $m$ — the number of red edges in your graph. Then, you should output $m$ lines, each containing two integers $a_{i}$ and $b_{i}$ , ( $1<=a_{i},b_{i}<=n$ , $a_{i}≠b_{i}$ ) which means that there is an undirected red edge between vertices $a_{i}$ and $b_{i}$ . Every red edge should be printed exactly once, you can print the edges and the vertices of every edge in arbitrary order.
Remember that PolandBall's graph should remain simple, so no loops or multiple edges are allowed.
输入输出样例
输入 #1
4 1
输出 #1
-1
输入 #2
5 2
输出 #2
4 1 2 2 3 3 4 4 5
In the first sample case, no graph can fulfill PolandBall's requirements.
In the second sample case, red graph is a path from $1$ to $5$ . Its diameter is $4$ . However, white graph has diameter $2$ , because it consists of edges 1-3, 1-4, 1-5, 2-4, 2-5, 3-5.
In the second sample case, red graph is a path from $1$ to $5$ . Its diameter is $4$ . However, white graph has diameter $2$ , because it consists of edges 1-3, 1-4, 1-5, 2-4, 2-5, 3-5.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted