A11687 | Degree Set
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a sequence of $n$ positive integers $d_{1},d_{2},...,d_{n}$ ( $d_{1}<d_{2}<...<d_{n}$ ). Your task is to construct an undirected graph such that:
- there are exactly $d_{n}+1$ vertices;
- there are no self-loops;
- there are no multiple edges;
- there are no more than $10^{6}$ edges;
- its degree set is equal to $d$ .
Vertices should be numbered $1$ through $(d_{n}+1)$ .
Degree sequence is an array $a$ with length equal to the number of vertices in a graph such that $a_{i}$ is the number of vertices adjacent to $i$ -th vertex.
Degree set is a sorted in increasing order sequence of all distinct values from the degree sequence.
It is guaranteed that there exists such a graph that all the conditions hold, and it contains no more than $10^{6}$ edges.
Print the resulting graph.
- there are exactly $d_{n}+1$ vertices;
- there are no self-loops;
- there are no multiple edges;
- there are no more than $10^{6}$ edges;
- its degree set is equal to $d$ .
Vertices should be numbered $1$ through $(d_{n}+1)$ .
Degree sequence is an array $a$ with length equal to the number of vertices in a graph such that $a_{i}$ is the number of vertices adjacent to $i$ -th vertex.
Degree set is a sorted in increasing order sequence of all distinct values from the degree sequence.
It is guaranteed that there exists such a graph that all the conditions hold, and it contains no more than $10^{6}$ edges.
Print the resulting graph.
输入格式
The first line contains one integer $n$ ( $1<=n<=300$ ) — the size of the degree set.
The second line contains $n$ integers $d_{1},d_{2},...,d_{n}$ ( $1<=d_{i}<=1000$ , $d_{1}<d_{2}<...<d_{n}$ ) — the degree set.
The second line contains $n$ integers $d_{1},d_{2},...,d_{n}$ ( $1<=d_{i}<=1000$ , $d_{1}<d_{2}<...<d_{n}$ ) — the degree set.
输出格式
In the first line print one integer $m$ ( $1<=m<=10^{6}$ ) — the number of edges in the resulting graph. It is guaranteed that there exists such a graph that all the conditions hold and it contains no more than $10^{6}$ edges.
Each of the next $m$ lines should contain two integers $v_{i}$ and $u_{i}$ ( $1<=v_{i},u_{i}<=d_{n}+1$ ) — the description of the $i$ -th edge.
Each of the next $m$ lines should contain two integers $v_{i}$ and $u_{i}$ ( $1<=v_{i},u_{i}<=d_{n}+1$ ) — the description of the $i$ -th edge.
输入输出样例
输入 #1
3 2 3 4
输出 #1
8 3 1 4 2 4 5 2 5 5 1 3 2 2 1 5 3
输入 #2
3 1 2 3
输出 #2
4 1 2 1 3 1 4 2 3
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted