Graph constructive problems are back! This time the graph you are asked to build should match the following properties.

The graph is connected if and only if there exists a path between every pair of vertices.

The diameter (aka "longest shortest path") of a connected undirected graph is the maximum number of edges in the shortest path between any pair of its vertices.

The degree of a vertex is the number of edges incident to it.

Given a sequence of n n integers a 1 ,a 2 ,…,a n  a1,a2,…,an construct a connected undirected graph of n n vertices such that:

  • the graph contains no self-loops and no multiple edges;
  • the degree d i  di of the i i -th vertex doesn't exceed a i  ai (i.e. d i ≤a i  di≤ai );
  • the diameter of the graph is maximum possible.

Output the resulting graph or report that no solution exists.

Input

The first line contains a single integer n n (3≤n≤500 3≤n≤500 ) — the number of vertices in the graph.

The second line contains n n integers a 1 ,a 2 ,…,a n  a1,a2,…,an (1≤a i ≤n−1 1≤ai≤n−1 ) — the upper limits to vertex degrees.

Output

Print "NO" if no graph can be constructed under the given conditions.

Otherwise print "YES" and the diameter of the resulting graph in the first line.

The second line should contain a single integer m m — the number of edges in the resulting graph.

The i i -th of the next m m lines should contain two integers v i ,u i  vi,ui (1≤v i ,u i ≤n 1≤vi,ui≤n , v i ≠u i  vi≠ui ) — the description of the i i -th edge. The graph should contain no multiple edges — for each pair (x,y) (x,y) you output, you should output no more pairs (x,y) (x,y) or (y,x) (y,x) .

Examples

Input
3
2 2 2
Output
YES 2
2
1 2
2 3
Input
5
1 4 1 1 1
Output
YES 2
4
1 2
3 2
4 2
5 2
Input
3
1 1 1
Output
NO

题意:构造一棵树,使得直径最长,需要满足每个点的度数di<=ai。

思路:我们选择ai最小的两个最为直径端点,然后把di>1的加到直径上去,剩下的度数为1的加到直径的枝桠上。

昨天没时间了没有写输出“NO”,WA3了。今天加上了就AC了。

给我30s可能就A了,加上最后一题水题没做。这一次CF血亏。

#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int N,sum,L,S,T;
int b[maxn],ans; int f[maxn],c[maxn],tot;
pii a[maxn];
int main()
{
scanf("%d",&N); ans=;
rep(i,,N) scanf("%d",&a[i].F),a[i].S=i;
sort(a+,a+N+);
b[++L]=a[].S; b[++L]=a[].S;
int pre=b[],bg=;
rep(i,,N){
if(a[i].F>){
f[++tot]=pre,c[tot]=a[i].S,pre=a[i].S,ans++;
if(!bg) bg=i;
}
}
f[++tot]=pre,c[tot]=b[];
int pos=bg,F=true;
rep(i,,bg-) {
if(a[i].F==) {
while(a[pos].F<=){
pos++; if(pos==N+) {F=false; break;}
}
if(!F) break;
a[pos].F--; f[++tot]=a[i].S,c[tot]=a[pos].S;
}
else break;
}
if(!F||tot!=N-) puts("NO");
else {
printf("YES %d\n%d\n",ans,N-);
rep(i,,tot) printf("%d %d\n",f[i],c[i]);
}
return ; }

CF1082D:Maximum Diameter Graph (简单构造)的更多相关文章

  1. cf1082D Maximum Diameter Graph(构造+模拟+细节)

    QWQ不得不说 \(cf\)的\(edu\ round\)出这种东西 有点太恶心了 题目大意:给你\(n\)个点,告诉你每个点的最大度数值(也就是说你的度数要小于等于这个),让你构造一个无向图,使其满 ...

  2. [CF1082D]Maximum Diameter Graph

    题目描述 Description Graph constructive problems are back! This time the graph you are asked to build sh ...

  3. Codeforces 1082D Maximum Diameter Graph (贪心构造)

    <题目链接> 题目大意:给你一些点的最大度数,让你构造一张图,使得该图的直径最长,输出对应直径以及所有的边. 解题分析:一道比较暴力的构造题,首先,我们贪心的想,要使图的直径最长,肯定是尽 ...

  4. Educational Codeforces Round 55 (Rated for Div. 2) D. Maximum Diameter Graph (构造图)

    D. Maximum Diameter Graph time limit per test2 seconds memory limit per test256 megabytes inputstand ...

  5. Educational Codeforces Round 55 (Rated for Div. 2):D. Maximum Diameter Graph

    D. Maximum Diameter Graph 题目链接:https://codeforces.com/contest/1082/problem/D 题意: 给出n个点的最大入度数,要求添加边构成 ...

  6. D. Maximum Diameter Graph 贪心+图论+模拟

    题意:给出n个点的度数列 上限(实际点可以小于该度数列)问可以构造简单路最大长度是多少(n个点要连通 不能有平行边.重边) 思路:直接构造一条长链  先把度数为1的点 和度数大于1的点分开  先把度数 ...

  7. CodeForces 1082 D Maximum Diameter Graph

    题目传送门 题意:现在有n个点,每个点的度数最大为di,现在要求你构成一棵树,求直径最长. 题解:把所有度数为2的点先扣出来,这些就是这颗树的主干,也就是最长的距离. 然后我们把度数为2的点连起来,之 ...

  8. Codeforces 1082 D. Maximum Diameter Graph-树的直径-最长链-构造题 (Educational Codeforces Round 55 (Rated for Div. 2))

    D. Maximum Diameter Graph time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  9. CF1157D N Problems During K Days(简单构造)

    题目 题目 原数据是水成啥样了,\(<\longrightarrow <=,>=\longrightarrow <=,\)这也能过 被\(hack\)后身败名裂 做法 简单的贪 ...

随机推荐

  1. iis6下配置支持.net4.0&发布网站[转]

    iis6配置支持.net4.0 在win2003操作系统上发布两个网站,首先配置iis: 1.下载 .net framework 4.0   差不多48MB 2.安装 3.打开iis: 开始=> ...

  2. 4.10 Routing -- Asynchronous Routing

    本节介绍了路由器的一些更高级的功能和处理复杂异步逻辑的能力. 一.A word on promises 1. 在Ember的Router中Ember使用了大量的Promises概念来处理异步逻辑.简而 ...

  3. mysql_escape_string — 转义一个字符串用于 mysql_query

    string mysql_escape_string ( string $unescaped_string ) 本函数将 unescaped_string 转义,使之可以安全用于 mysql_quer ...

  4. Redis 入门之Redis简介

    Reids 是一个开源的高性能键值对数据库.它通过多种键值数据类型来适应不同场景下的存储需求,并借助许多高层级的接口使其可以胜任如缓存.队列系统等不同的角色. 1.Reids的诞生 Redis到底是在 ...

  5. VMware Vcenter Server 6.0忘记密码

    windows 版Vcenter6.0 重置密码首先要登录到安装Vcenter的windows服务器上 用管理员身份打开CMD命令行 进入VMware VCenter的目录 默认是C:\Program ...

  6. 【问题解决:未找到端口号】启动报错Circular placeholder reference 'server.port' in property definitions

    问题描述: 启动spring boot项目时报错:Circular placeholder reference 'server.port' in property definitions 解决过程: ...

  7. 例子.ZC简单.JSP和session

    1.环境: Win7x64.E:\ZC_IDE\Eclipse\Windows\eclipse-jee-mars-R-win32__apk__20180122_1457\eclipse.exe.E:\ ...

  8. javascript之反柯里化(uncurrying)

    在JavaScript中,当我们调用对象的某个方法时,其实不用去关心该对象原本是否被设计为拥有这个方法,这是动态类型语言的特点.可以通过反柯里化(uncurrying)函数实现,让一个对象去借用一个原 ...

  9. 递归--练习11--noi9273 PKU2506Tiling

    递归--练习11--noi9273 PKU2506Tiling 一.心得 25 a[i]%=10;(高精度时) 26 这里错了,花了好久改好 27 28 29 int* f(int n){ 30 if ...

  10. 这些HTML、CSS知识点,面试和平时开发都需要 No1-No4(知识点:HTML、CSS、盒子模型、内容布局)

    这些HTML.CSS知识点,面试和平时开发都需要 No1-No4   系列知识点汇总 这些HTML.CSS知识点,面试和平时开发都需要 No1-No4(知识点:HTML.CSS.盒子模型.内容布局) ...