/// Determine whether the degree of each point is a simple graph # include <stdio. h> # include <algorithm> # include <string. h> using namespace STD; int A [1010]; bool CMP (int x, int y) {return x> Y;} int main () {int t, n, I, j; scanf ("% d", & T); While (t --) {int flag = 1; scanf ("% d", & N ); for (I = 0; I <n; I ++) scanf ("% d", & A [I]); sort (A, A + N, CMP ); while (A [0] & A [n-1]> = 0) {int I = 1; while (A [0] --) {-- A [I ++];} + + A [0]; sort (A, A + N, CMP);} if (a [n-1] <0) printf ("NO \ n "); else printf ("Yes \ n");} return 0 ;}
1. the Havel-Hakimi theorem is mainly used to determine whether a given sequence is linear.
2. First, we will introduce the degree sequence: If the degrees of all vertices in graph G are arranged in a sequence S, S is called the degree sequence of graph G.
3. If a finite sequence composed of non-negative integers is an undirected graph sequence, it is called a sequence.
4. determination process: (1) sort the current sequence in descending order, and (2) sort the subsequent s numbers-1 from S [2, (3) keep repeating until the current sequence shows a negative number (that is, if it is not a sequence) or the current sequence is all 0 (sequence) and exits.
5. For example, sequence S: 7, 7, 4, 3, 3, deletes the first item 7 of sequence S, minus 1 for each of the following seven items, and obtains: 6, 3, 2, 2, 1, 0. Continue to delete the first item 6 of the sequence, and subtract 1 from each item of the next six items to get:, 0,-1. A negative number occurs at this step, therefore, this sequence cannot be illustrated.
HDU 2454 degree sequence of graph G (judge a simple graph)