首页 > 代码库 > 关于可图化序列的一点结论 NEU 1429
关于可图化序列的一点结论 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 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 and 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>
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]&1) return 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",°[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\n");
40 else printf("NO\n");
41 }
42 }
43
44 /**************************************************************
45 Problem: 1429
46 User: 20124906
47 Language: C++
48 Result: 正确
49 Time:201 ms
50 Memory:1960 kb
51 ****************************************************************/