CF976D.Degree Set

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 106 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 106 edges.

Print the resulting graph.

给你一个长度为 nn 的正整数序列 d1, d2, ..., dnd_1,\,d_2,\,...,\,d_n(满足 d1<d2<⋯<dnd_1 < d_2 < \dots < d_n)。你的任务是构造一个无向图,使其满足以下条件:

  • 图中恰好有 dn+1d_n + 1 个顶点;
  • 图中不存在自环;
  • 图中不存在重边;
  • 图中的边数不超过 10610^6;
  • 图的度集(degree set)恰好等于序列 dd。

顶点编号应为 11 到 dn+1d_n + 1。

度序列(degree sequence)是一个长度等于图中顶点数的数组 aa,其中 aia_i 表示与第 ii 个顶点相邻的顶点个数。

度集(degree set)是将度序列中所有互不相同的值按升序排列后得到的序列。

题目保证:存在满足上述所有条件的图,且其边数不超过 10610^6。

请输出所构造的图。

输入格式

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.

第一行包含一个整数 nn(1≤n≤3001 \leq n \leq 300)—— 度数集合的大小。

第二行包含 nn 个整数 d1,d2,…,dnd_1, d_2, \ldots, d_n(1≤di≤10001 \leq d_i \leq 1000,且 d1<d2<…<dnd_1 < d_2 < \ldots < d_n)—— 度数集合。

输出格式

In the first line print one integer m (1 ≤ m ≤ 106) — 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 106 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.

第一行输出一个整数 mm(1≤m≤1061 \leq m \leq 10^6)—— 表示所构造图中的边数。保证存在满足所有条件的图,且其边数不超过 10610^6。

接下来的 mm 行中,每行应包含两个整数 viv_i 和 uiu_i(1≤vi, ui≤dn+11 \leq v_i,\, u_i \leq d_n + 1)—— 描述第 ii 条边。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页