Graphic Sequence

A graphic sequence is a sequence of numbers which can be the degree sequence of some graph. A sequence can be checked to determine if it is graphic using GraphicQ[g] in the Mathematica package Combinatorica` .

Erdős and Gallai (1960) proved that a degree sequence  is graphic iff the sum of vertex degrees is even and the sequence obeys the property

for each integer  (Skiena 1990, p. 157), and this condition also generalizes to directed graphs. Tripathi and Vijay (2003) showed that this inequality need be checked only for as many  as there are distinct terms in the sequence, not for all .

Havel (1955) and Hakimi (1962) proved another characterization of graphic sequences, namely that a degree sequence with =3" style="border-width: 0px; vertical-align: middle;"> and =1" style="border-width: 0px; vertical-align: middle;"> is graphical iff the sequence  is graphical. In addition, Havel (1955) and Hakimi (1962) showed that if adegree sequence is graphic, then there exists a graph  such that the node of highest degree is adjacent to the  next highest degree vertices of , where  is the maximum degree of .

No degree sequence can be graphic if all the degrees occur with multiplicity 1 (Behzad and Chartrand 1967, p. 158; Skiena 1990, p. 158). Any degree sequence whose sum is even can be realized by a multigraph having loops (Hakimi 1962; Skiena 1990, p. 158).

很不错的一个定理: 就是给出一个度序列,然后 判读这个度序列是不是可图的当且仅当 满足 : sigma<1,r>(di) <= k*(k-1) +sigma<k+1,n> min(k,di)

(    0< k<=n   )

注意到定理中要求 sigma<k+1,n> min(k,di) ; 所以我们可以二分找出度数大于k的区间求出其前缀和即可 时间复杂的达到 O(nlogn) 然后套公式就行了。

其实还有另外一个定理: havel定理,不是怎么实用的定理感觉是 。 网上题解代码 复杂度都是O(n^2logn) 没事水数据玩都是。  还扯些没用的优化,

好像可以计数排序写复杂度是O(n^2) 省赛还是被卡掉的。 O(nlogn) 还挺快>_<。

给出一道题:

1429: Traveling

题目描述

SH likes traveling around the world. When he arrives at a city, he will ask the staff about the number of cities that connected with this city directly. After traveling around a mainland, SH will collate data and judge whether the data is correct.

A group of data is correct when it can constitute an undirected graph.

输入

There are multiple test cases. The first line of each test case is a positive integer N (1<=N<=10000) standing for the number of cities in a mainland. The second line has N positive integers a1, a2, ...,an. ai stands for the number of cities that connected directly with the ith city. Input will be ended by the END OF FILE.

输出

If a group of data is correct, output "YES" in one line, otherwise, output "NO".

样例输入

8 7 7 4 3 3 3 2 1 10 5 4 3 3 2 2 2 1 1 1 

样例输出

NO YES

1 #include<cstdio>

 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int MAX = 1e5;
 6 int deg[MAX],sum[MAX],sum2[MAX];
 7 int cmp(int a,int b) {return a>b ;}
 8 int n;
 9 int check() {
     if(sum[n]&) return ;
     for(int k=;k<=n;k++) {
        int L=k+,R=n; int ans;
        while(L<=R) {
             int mid=(R+L) >> ;
             if(deg[mid]>=k) ans=mid,L=mid+;
             else R=mid-;
        }
        sum2[k]=k*(ans-k)+sum[n]-sum[ans];
     }
     int ans;
     for(int i=;i<=n;i++) {
         if(sum[i]<=i*(i-)) continue;
         ans=sum2[i];
        // for(int k=i+1;k<=n;k++) ans+=min(i,deg[k]);
         if(sum[i]>i*(i-)+ans) return ;
  
     }
     return ;
 }
  
 int main() {
     while(scanf("%d",&n)==) {
         memset(sum,,sizeof(sum));
         memset(sum2,,sizeof(sum2));
         for(int i=;i<=n;i++) scanf("%d",&deg[i]);
         sort(deg+,deg+n+,cmp);
         for(int i=;i<=n;i++) sum[i]=sum[i-] + deg[i];
         int ret=check();
         if(ret) printf("YES\n");
         else printf("NO\n");
     }
 }
  
 /**************************************************************
     Problem: 1429
     User: 20124906
     Language: C++
     Result: 正确
     Time:201 ms
     Memory:1960 kb
 ****************************************************************/

关于可图化序列的一点结论 NEU 1429的更多相关文章

  1. Havel--Hakimi定理推断可图化 python

    介绍: 哈维尔[1955]--哈吉米[1962]算法能够用来判读一个度序列d是否是可图化的. 哈维尔[1955]--哈吉米[1962]定理: 对于N > 1,长度为N的度序列d可以可图化当且仅当 ...

  2. UML精粹3 - 类图,序列图,CRC

    类图Class diagram 类图描述系统中的对象类型,以及它们之间的各种静态关系.类图也展示类的性质和操作,以及应用于对象连接方式的约束.UML中的特性feature,涵盖了性质property和 ...

  3. Havel-Hakimi定理---通过度数列判断是否可图化

    0.可图:一个非负整数组成的序列如果是某个无向图的度序列,则该序列是可图的. 1.度序列:Sequence Degree,若把图G所有顶点的度数排成一个序列,责成该序列为图G的一个序列.该序列可以是非 ...

  4. 从 Java 代码逆向工程生成 UML 类图和序列图

    from:http://blog.itpub.net/14780914/viewspace-588975/ 本文面向于那些软件架构师,设计师和开发人员,他们想使用 IBM® Rational® Sof ...

  5. Android图表库MPAndroidChart(七)—饼状图可以再简单一点

    Android图表库MPAndroidChart(七)-饼状图可以再简单一点 接上文,今天实现的是用的很多的,作用在统计上的饼状图,我们看下今天的效果 这个效果,我们实现,和之前一样的套路,我先来说下 ...

  6. 【51Nod】1510 最小化序列 贪心+动态规划

    [题目]1510 最小化序列 [题意]给定长度为n的数组A和数字k,要求重排列数组从而最小化: \[ans=\sum_{i=1}^{n-k}|A_i-A_{i+k}|\] 输出最小的ans,\(n \ ...

  7. poj 1659 Frogs&#39; Neighborhood 度序列可图化 贪心

    题意: 对一个无向图给出一个度序列,问他是否可简单图化. 分析: 依据Havel定理,直接贪心就可以. 代码: //poj 1659 //sep9 #include <iostream> ...

  8. Visio画UML类图、序列图 for Java

    参考文档: 1.百度搜索: 怎样用Visio 2007画C++类图 连接 https://jingyan.baidu.com/article/9f7e7ec07286e16f281554f7.html ...

  9. 【BZOJ1049】【Luogu P2501】 [HAOI2006]数字序列 DP,结论,LIS

    很有(\(bu\))质(\(hui\))量(\(xie\))的一个题目. 第一问:求最少改变几个数能把一个随机序列变成单调上升序列. \(Solution:\)似乎是一个结论?如果两个数\(A_i\) ...

随机推荐

  1. convert命令

    可以修改图片的分辨率 convert -resize 600×600 src.jpg dst.jpg src.jpg是你要修改的图片的名字 dst.jpg是新生成的图片名字

  2. BundleConfig的作用

    在ASP.NET MVC4中(在WebForm中应该也有),有一个叫做Bundle的东西,它用来将js和css进行压缩(多个文件可以打包成一个文件),并且可以区分调试和非调试,在调试时不进行压缩,以原 ...

  3. SpringBoot学习1:创建第一个SpringBoot项目

    一.新建项目 二.打开项目的pom文件,在里面添加maven依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.s ...

  4. 问题001:Java软件,属于系统软件还是应用软件呢?

    在学习Java前要掌握的一些小问题: 问题一:Java软件,属于系统软件还是应用软件呢? java语言应用在计算机系统上,首先应知道计算机系统分为几部分? 计算机系统由硬件系统和软件系统两部分构成.硬 ...

  5. 抽屉head部分,hover应用,鼠标放上变色

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 十七、MySQL UNION 操作符

    MySQL UNION 操作符 本教程为大家介绍 MySQL UNION 操作符的语法和实例. 描述 MySQL UNION 操作符用于连接两个以上的 SELECT 语句的结果组合到一个结果集合中.多 ...

  7. Python_深浅拷贝

    深浅拷贝 ‘copy’和'='的区别:copy会开辟一个新的空间,而‘=’不会. 浅copy只会copy第一层,再里边的就进行共享了. 需要记住的是copy之后记住的是内存寻址地址,而浅copy时如果 ...

  8. Python中字符串String的基本内置函数与过滤字符模块函数的基本用法

    Python中字符串String的基本内置函数与用法 首先我们要明白在python中当字符编码为:UTF-8时,中文在字符串中的占位为3个字节,其余字符为一个字节 下面就直接介绍几种python中字符 ...

  9. 面试前赶紧看了5道Python Web面试题,Python面试题No17

    目录 本面试题题库,由公号:非本科程序员 整理发布 第1题: Flask中的请求上下文和应用上下文是什么? 第2题:django中间件的使用? 第3题: django开发中数据做过什么优化? 第4题: ...

  10. Artwork 18年中南多校第一场A

    一.题意 对于一个矩阵,若干道命令,每道命令将会把某一段格子涂黑,请问每次涂黑之后矩阵中未被涂黑的块的数量? 二.思路 保存每道命令,并且忠实的执行他,到最后一步开始搜索联通块的数量,并将其保存. 之 ...