Graph Reconstruction Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Let there be a simple graph with N vertices but we just know the degree of each vertex. Is it possible to reconstruct the graph only by these information? A sim…
题意 题目链接 \(T\)组数据,给出\(n\)个点的度数,问是否可以构造出一个简单图 Sol Havel–Hakimi定理: 给定一串有限多个非负整数组成的序列,是否存在一个简单图使得其度数列恰为这个序列. 令\(S=(d_1,d_2,\dots,d_n)\)为有限多个非负整数组成的非递增序列. S可简单图化当且仅当有穷序列\(S'=(d_2-1,d_3-1,...,d(d_1+1)-1,d(d_1+2),...,d_n)\)只含有非负整数且是可简单图化的. 最后判断一下是否都是零就好了 感觉…
题目链接 Graph Reconstruction 题意 给你无向图每个点的度数, 问是否存在唯一解, 存在输出唯一解, 多解输出两个, 无解输出IMPOSSIBLE 思路 这里用到了 Havel-Hakimi定理, 实际上就是按照度数构图的一种贪心策略. 这样能判断出来一个解或无解, 多解的情况, 只要在比较构图时最后面两个点的当前度数一样, 那么选其一都是可行的, 但是选其一的情况有保证了另外一个肯定没有连上, 所以能找到其它解. 代码 #include <bits/stdc++.h> #…
C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/problem/C Description I have an undirected graph consisting of n nodes, numbered 1 through n. Each node has at most two incident edges. For each pa…
Hypersphere Time Limit: 1 Second       Memory Limit: 32768 KB In the world of k-dimension, there's a large hypersphere made by mysterious metal. People in the world of k-dimension are performing a ceremony to worship the goddess of dimension. They ar…
Graph Reconstruction Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Let there be a simple graph with N vertices but we just know the degree of each vertex. Is it possible to reconstruct the graph only by these information? A sim…
分析: 给定一个非负整数序列{dn},若存在一个无向图使得图中各点的度与此序列一一对应,则称此序列可图化. 进一步,若图为简单图,则称此序列可简单图化 (来自百度百科) 可简单图化的判定可以用Havel-Hakimi定理,然后简述 Havel-Hakimi定理 Havel-Hakimi定理的过程: 1,按度数排序. 2,选取度数最大的点,如果该点度数为0,结束,有解 3,每次选一个度数最大的点,然后将后面的点的度数依次减1,表示该顶点和相应的顶点有边相连, 如果有点的度数减到负数,结束,无解.…
题意 给你一个度序列,问能否构成一个简单图. 分析 对于可图化,只要满足度数之和是偶数,即满足握手定理. 对于可简单图化,就是Heavel定理了. Heavel定理:把度序列排成不增序,即 $deg[1] \geq deg[2] \geq ... \geq deg[V]$,则 $deg$ 可简单图化当且仅当 ${deg}' = \{deg[2]-1, deg[3]-1,...,deg[deg[1]+1]-1,...,deg[v] \}$ 可简单图化. 简单地说,把 $deg$ 从大到小排序后,找…
1001: 签到题,二分一下即可 代码: #include <set> #include <map> #include <cmath> #include <ctime> #include <queue> #include <stack> #include <cstdio> #include <string> #include <vector> #include <cstdlib> #in…
Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student names. However, there are too many students, so I failed. It is a shame, so I don't want my students to know this. Whenever I need to call someone, I c…