关于判断可图、图单连通性几题
来源:互联网 发布:mysql数据库技术 编辑:程序博客网 时间:2024/06/05 07:30
1、输入一个图的度数列判断是否可图。
省赛原题。 SX数据。 (现在想想那个一A真是莫明其妙,不过卡了后面的题也算是败了RP吧。)
原题链接在此:http://acm.hdu.edu.cn/showproblem.php?pid=2454
未名湖一题在此:http://poj.org/problem?id=1659
以上两题用HH(判断可图的)贪心都可以过,复杂度要求不是很高。
Erdős–Gallai theorem 链接:http://en.wikipedia.org/wiki/Erd%C5%91s%E2%80%93Gallai_theorem
A sequence of non-negative integers can be represented as the degree sequence of a finite simple graph on n vertices if and only if is even and
holds for .
orz xl大牛
附个O(n*log(n))的代码
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 1e5+1;int N, a[maxn];LL s[maxn];inline void init() { memset(s, 0, sizeof(s));}int main(){ int T; scanf("%d", &T); while(T--){ scanf("%d", &N); { init(); for (int i=1; i<=N; ++i) { scanf ("%d", &a[i]); a[i] = -a[i]; } sort(a+1, a+N+1); for (int i=1; i<=N; ++i) { s[i] = s[i-1]-a[i]; } if (s[N]%2==1) { printf ("no\n"); continue; } bool flag = true; for (int r=1; r<=N; ++r) { int pos = upper_bound(a+r+1, a+N+1, -r)-a; if (s[r]> 1LL*r*(r-1)+ s[N]-s[pos-1]+ 1LL*r*(pos-r-1)) { flag = false; break; } } printf ("%s\n", flag ? "yes" : "no"); } } return 0;}
2、判单连通。
原题在此: http://poj.org/problem?id=2186
简单思路:缩点后,能有一条链经过所有的强连通分量。
ps:图论真是很巧妙又很开阔思维的,YY一条链...
图论继续搞起。
admin那个并查集思路果断AC不了数据强的题。。。
标程真是奇葩。
不附代码了,网上好多。
- 关于判断可图、图单连通性几题
- 判断图的连通性
- 图的连通性判断
- 判断图的连通性
- 判断图的连通性
- 图的连通性判断
- 图的连通性判断算法
- [图]深搜判断图的连通性
- 判断图连通性的三种方法
- 图的连通性判断(算法实现)
- 拦截匪徒 (枚举+判断图的连通性)
- 【学习笔记】关于图论中的连通性
- 判断无向图图的连通性,邻接矩阵表示
- hdu 1878 欧拉回路,图的连通性判断
- 图的连通性强弱判断(tarjan+缩点)
- 图的连通性小结
- 图的连通性
- 图论连通性历程
- android密码显示与隐藏实现
- 2014-05-14:MFC recvfrom函数
- SLF4J 的几种实际应用模式--之二:SLF4J+Logback
- Jni中C++和Java的参数传递
- she012编译OpenSSL
- 关于判断可图、图单连通性几题
- windows下解压的问题(解决reveal、google)
- 向linux内核添加系统调用新老内核比较
- commondatastorage.googleapis.com访问失败快速解决
- CString的16进制转换成BYTE数组
- Django admin界面出现 Incorrect string value 错误
- hbase 之 split
- 如何快速编译hal层的修改
- SLF4J 的几种实际应用模式--之三:JCL-Over-SLF4J+SLF4J