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 ****************************************************************/


  • 相关阅读:
    mongodb性能测试:long时间戳与string格式时间
    .netcore mongodb 分页+模糊查询+多条件查询
    .netcore 图片处理
    ELEMENT-UI 封装el-table 局部刷新row
    vue-upload 封装组件-上传组件
    vue实现v-model父子组件间的双向通信
    cc.AudioSource
    Chrome插件:本地程序实现验证码破解(浏览器与本地进程通信)
    Chrome插件:微信公众号自动登录(chrome.extension)
    Chrome插件:浏览器后台与页面间通信
  • 原文地址:https://www.cnblogs.com/acvc/p/3750548.html
Copyright © 2011-2022 走看看