ZOJ3732 Graph Reconstruction(图的构造)
来源:互联网 发布:基金南方大数据300 编辑:程序博客网 时间:2024/05/31 18:43
主要坑在了多解时,假设最多的度数是 d 则 a[d+2] == a[d+1] 时,d+1 和 d+2 是可以互换的。但是互换只限于发现这对点之后加到图里的边,开始全部互换了错了很多次。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 101;struct node { int num, deg; bool operator<(const node &b)const {return deg > b.deg;}}a[maxn];int u[maxn*maxn], v[maxn*maxn];int main(){ int n; while (~scanf("%d", &n)) { memset(u, 0, sizeof(u)); memset(v, 0, sizeof(v)); for (int i = 0; i < maxn; i++) a[i].num = a[i].deg = 0; bool ok = true, uni = true; int x, y, cnt = 0, sum = 0, bcnt = 0; for (int i = 0; i < n; i++) { a[i].num = i+1; scanf("%d", &a[i].deg); sum += a[i].deg; } if (sum & 1) { puts("IMPOSSIBLE"); continue; } for (int i = 0; ok && i < n; i++) { sort(a+i, a+n); if (a[i].deg == 0) break; for (int j = 1; j <= a[i].deg; j++) { if (j == a[i].deg && i+j+1 < n && a[i+j].deg == a[i+j+1].deg) { uni = false; x = a[i+j].num, y = a[i+j+1].num; bcnt = cnt; } if (i+j >= n || --a[i+j].deg < 0) { ok = false; break; } u[cnt] = a[i].num; v[cnt] = a[i+j].num; cnt++; } } if (!ok) puts("IMPOSSIBLE"); else if (uni) { printf("UNIQUE\n%d %d\n", n, cnt); for (int i = 0; i < cnt; i++) printf("%d%c", u[i], i == cnt-1 ? '\n' : ' '); for (int i = 0; i < cnt; i++) printf("%d%c", v[i], i == cnt-1 ? '\n' : ' '); } else { printf("MULTIPLE\n%d %d\n", n, cnt); for (int i = 0; i < cnt; i++) printf("%d%c", u[i], i == cnt-1 ? '\n' : ' '); for (int i = 0; i < cnt; i++) printf("%d%c", v[i], i == cnt-1 ? '\n' : ' '); printf("%d %d\n", n, cnt); for (int i = 0; i < cnt; i++) { if (i >= bcnt) { if (u[i] == x) u[i] = y; else if (u[i] == y) u[i] = x; } printf("%d%c", u[i], i == cnt-1 ? '\n' : ' '); } for (int i = 0; i < cnt; i++) { if (i >= bcnt) { if (v[i] == x) v[i] = y; else if (v[i] == y) v[i] = x; } printf("%d%c", v[i], i == cnt-1 ? '\n' : ' '); } } } return 0;}
0 0
- ZOJ3732 Graph Reconstruction(图的构造)
- zoj 3732 Graph Reconstruction(构造)
- zoj 3732 Graph Reconstruction(构造)
- zoj 3732 Graph Reconstruction 构造
- Graph Reconstruction
- 构造字符串(hdu2970Suffix reconstruction)
- hdu 3732 Graph Reconstruction
- HDU 4797 Graph Reconstruction
- Graph Reconstruction ZOJ
- bzoj 4319: cerc2008 Suffix reconstruction(构造)
- ZOJ 3732 Graph Reconstruction (Havel-Hakimi定理)
- zoj3732(度序列判断是否可图且是否唯一)
- “玲珑杯”ACM比赛 Round #4 F -- My-graph【图的同构(构造)】
- [BZOJ4319]cerc2008 Suffix reconstruction(贪心+构造+后缀数组)
- ZOJ-3732 Graph Reconstruction(判定无向图度数序列能否可图化)
- ZOJ 3732 2013 ACM/ICPC 长沙赛区现场赛G题 Graph Reconstruction (图论)
- Codeforces Round #192 (Div. 1) C. Graph Reconstruction (随机化算法)
- zoj 3732 Graph Reconstruction(Havel-Hakimi定理)
- python 爬虫试手,好简单的爬虫
- ZOJ3735 Josephina and RPG(简单DP)
- 学习笔记_JFame事件处理的三种方法(1)直接实现法
- TreeMap学习
- 哥特人动画版丰田个地方被覆盖
- ZOJ3732 Graph Reconstruction(图的构造)
- 01背包基础 (杭电2602)
- OC之KVO
- 【HDU 4902 多校联合】Nice boat【线段树】
- 秩序
- Building a Space Station(Prim)
- 学习笔记_JFame事件处理的三种方法(2)内部类实现
- HDU 1710 Binary Tree Traversals
- ASP.NET MVC学习---(三)EF简单增删改查