zoukankan      html  css  js  c++  java
  • 关于可图化序列的一点结论 NEU 1429

    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 {d_1,...,d_n} is graphic iff the sum of vertex degrees is even and the sequence obeys the property

     sum_(i=1)^rd_i<=r(r-1)+sum_(i=r+1)^nmin(r,d_i)

    for each integer r<=n-1 (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 r as there are distinct terms in the sequence, not for all 1<=r<=n-1.

    Havel (1955) and Hakimi (1962) proved another characterization of graphic sequences, namely that a degree sequence with n />=3 and d_1 />=1 is graphical iff the sequence {d_2-1,d_3-1,...,d_(d_1+1)-1,d_(d_1+2),...,d_p} is graphical. In addition, Havel (1955) and Hakimi (1962) showed that if adegree sequence is graphic, then there exists a graph G such that the node of highest degree is adjacent to the Delta(G) next highest degree vertices of G, where Delta(G) is the maximum degree of G.

    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() {
    10     if(sum[n]&1return 0;
    11     for(int k=1;k<=n;k++) {
    12        int L=k+1,R=n; int ans;
    13        while(L<=R) {
    14             int mid=(R+L) >> 1;
    15             if(deg[mid]>=k) ans=mid,L=mid+1;
    16             else R=mid-1;
    17        }
    18        sum2[k]=k*(ans-k)+sum[n]-sum[ans];
    19     }
    20     int ans;
    21     for(int i=1;i<=n;i++) {
    22         if(sum[i]<=i*(i-1)) continue;
    23         ans=sum2[i];
    24        // for(int k=i+1;k<=n;k++) ans+=min(i,deg[k]);
    25         if(sum[i]>i*(i-1)+ans) return 0;
    26  
    27     }
    28     return 1;
    29 }
    30  
    31 int main() {
    32     while(scanf("%d",&n)==1) {
    33         memset(sum,0,sizeof(sum));
    34         memset(sum2,0,sizeof(sum2));
    35         for(int i=1;i<=n;i++) scanf("%d",&deg[i]);
    36         sort(deg+1,deg+n+1,cmp);
    37         for(int i=1;i<=n;i++) sum[i]=sum[i-1] + deg[i];
    38         int ret=check();
    39         if(ret) printf("YES ");
    40         else printf("NO ");
    41     }
    42 }
    43  
    44 /**************************************************************
    45     Problem: 1429
    46     User: 20124906
    47     Language: C++
    48     Result: 正确
    49     Time:201 ms
    50     Memory:1960 kb
    51 ****************************************************************/


  • 相关阅读:
    oracle update join
    ResultSet转换为List的方法
    oracle创建用户操作
    ArcGIS打开工具无响应
    当前不会命中断点。源代码与原始版本不同
    使用Skin Editor自定义主题皮肤
    Spring boot项目设置加载静态资源的路径(spring.resources.static-locations)
    linux下文件的复制、移动与删除
    【珍藏】清华大学状元笔记 (初中+高中)全套高清笔记电子版 PDF
    【珍藏】全付费 (共204本)图灵程序设计丛书 高清电子书 带书签 PDF
  • 原文地址:https://www.cnblogs.com/acvc/p/3750548.html
Copyright © 2011-2022 走看看