[Question]
  [
Non-metals typically\* have a fixed number of covalent bonds in every chemical they are part of. Given the number of bonds every element requires, output whether it's possible to construct a *single* molecule from the given chemicals, such that every atom has it's desired number of bonds.
In other words, output if it's possible to construct a connected undirected multigraph without self-loops so that each node has the number of edges equal to the corresponding number listed in the input.
## Test Cases
Falsey:
* `[1]` A single element has nothing to bond with
* `[4]` Atoms can not bond with themselves
* `[1, 1, 1, 1]` Each atom is saturated after single bond, so it's impossible to connect all 4 of them together. It can form 2 pairs but not a single molecule.
* `[0, 0]` Two separate helium "molecules"
* `[1, 3]`
* `[2, 3]`
* `[1, 1, 1, 1, 1, 3]`
Truthy:
* `[1, 1]` (Hydrogen Gas: H-H → `1-1`)
* `[4, 2, 2]` (Carbon Dioxide: O=C=O → `2=4=2`)
* `[3, 3]` (Nitrogen Gas: N≡N → `3≡3`)
* `[2, 2, 2]` (Ozone\*: \$\newcommand{\tripow}[3]{ \_{#1}{\stackrel{#2}{\triangle}}\_{#3}} \tripow{O}{O}{O}\$ → \$\tripow{2}{2}{2}\$)
* `[0]` (Helium: He → `0`)
* `[3, 2, 1]` (Nitroxyl: O=N-H → `2=3-1`)
* `[3, 3, 3, 3]` (Tetrazete: \$\begin{array}{ccccccc}N&-&N& &3&-&3\\\
||& &||& → &||& &||\\\
N&-&N& &3&-&3\end{array}\$)
* `[4, 1, 1, 1, 1, 2, 2, 2]`
* `[4, 2, 2, 1, 1]`
* `[3, 3, 2, 1, 1]`
Here are the Falsey/Truthy test cases as two lists of lists:
```
[[1], [4], [1, 1, 1, 1], [0, 0], [1, 3], [2, 3], [1, 1, 1, 1, 1, 3]]
[[1, 1], [4, 2, 2], [3, 3], [2, 2, 2], [0], [3, 2, 1], [3, 3, 3, 3], [4, 1, 1, 1, 1, 2, 2, 2], [4, 2, 2, 1, 1], [3, 3, 2, 1, 1]]
```
## Clarifications
* You may assume the input is non-empty and all values are positive or zero.
* You may choose any 2 distinct values for truthy or falsy, or output truthy/falsy using your language's convention (swapping is allowed). See the tag wiki [decision-problem](/questions/tagged/decision-problem "show questions tagged 'decision-problem'")
\*I've been told real chemistry is a lot more complex than this, but you can ignore the complexities in this challenge.
  
[Answer]
# [Python 3](https://docs.python.org/3/), ~~61 60 59 58~~ 51 bytes
```
lambda x:len(x)-2<~sum(x)%2*all(x)*sum(x)/2>=max(x)
```
[Try it online!](https://tio.run/##bU/LDoMgEDzXr@DSKIamgpxM7bFf0Jv1sE01miAaH4le@usUFFNNGzbszjDDQDP1RS1DlccPJaB6vgCNkcikN@ITu7y7odLTkfkghB78BZ/ZNa5g1JNq2lL2nnsD0WVT5GInr1sEqJQoSWhKUMLNRgmyZVBAUGDZ0HRm@1c113rGjDyNnMOSBQTlHmDs2Oh7O/TFT7SN4rOdmTHc3ThTgeWZVRvJUta7fc7Gx1dEd8YNwQknoV6U7KBef36iPg "Python 3 – Try It Online")
-1 thanks to @Kevin Cruijssen
-7 thanks to @xnor
Uses theorem 2 from [this paper](https://www.semanticscholar.org/paper/On-Realizability-of-a-Set-of-Integers-as-Degrees-of-Hakimi/83b1608fb33eef2467a53f6ccffed559df7408dc).
It says a degree sequence is realizable as a connected multigraph with no self-loops if and only if it is `[0]`, or:
0. All degrees are positive.
1. The sum of the degree sequence is even.
2. The biggest degree is less than or equal to the sum of the rest of the degrees. That is, `sum(x)-max(x)>=max(x)`, or equivalently `sum(x)/2>=max(x)`
3. The number of edges, which is half the sum of degrees, is greater or equal to \$n-1\$, where \$n\$ is the number of vertices.
`~sum(x)%2*all(x)*sum(x)/2` is equal to `sum(x)/2` is the first two conditions are satisfied, and `0` otherwise.
If it is equal to `0`, it implies `len(x)-2<0>=max(x)`, so `len(x)==1, max(x)==0` and therefore `x==[0]`.
Otherwise, if the first two conditions are satisfied, it tests the third condition with `sum(x)/2>=max(x)`, and the fourth with `len(x)-2<sum(x)/2` (which is equivalent to `len(x)-1<=sum(x)/2` since these are integers according to the second condition).
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 134 bytes
Thanks to all for the motivation to immerse in graph theory! It is wonderful that there is a numerical criterion for connected multigraph. But I was wondering how it worked.  
So I didn’t make a port of the same theorem, but I found *an algorithm* that allows you to build a multigraph, if it's possible, or give a message that you can’t. Having studied [this article](https://arxiv.org/abs/2009.03747).  
Here is the full-code version of Theorem 7 from the paper. It takes list of degrees and print out:
* Render of graph and `True`, if it's possible to make connected multigraph
* Graph and `False`, if only non-connected result is possible
* `None`, if list of degrees is non-graphic
```
multiGraphFromDegrees[degrees_List] :=
  Module[{n = Length@degrees, graph = Graph[{}]},
   data = MapThread[{#1, #2} &, {degrees, Range@n}];
   While[n > 1,
    data = ReverseSortBy[data, First];
    data[[1, 1]] -= 1; data[[n, 1]] -= 1;
    graph = 
     EdgeAdd[graph, UndirectedEdge[data[[1, 2]], data[[n, 2]]]];
    data = Select[data, #[[1]] > 0 &];
    n = Length@data;
    ];
   If[n > 0, Print["None"],
    Row[{graph, " Connected: ", ConnectedGraphQ@graph}]
    ]];
```
Example `[1, 1, 1, 1, 1, 3]`:
[![enter image description here](https://i.stack.imgur.com/CZX5X.png)](https://i.stack.imgur.com/CZX5X.png)
Example `[3, 3, 3, 3]`:
[![enter image description here](https://i.stack.imgur.com/foOG6.jpg)](https://i.stack.imgur.com/foOG6.jpg)
Example `[6, 6, 4]`:
[![enter image description here](https://i.stack.imgur.com/BDxKM.jpg)](https://i.stack.imgur.com/BDxKM.jpg)
Example `[5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1]`:
[![enter image description here](https://i.stack.imgur.com/9JFlc.jpg)](https://i.stack.imgur.com/9JFlc.jpg)
Note, that algorithm makes *some example* of graph, if it's possible. So for `[3,3,3,3]` we have not Tetrazet, but other valid chemical. Also result *may be non-planar*, but it's OK for chemicals too.
And here is short version, directly answers the question of challenge (`True` or `False`):
```
(d=#;n=Length@#;Catch[While[n>1,d=ReverseSort[d];d[[1]]-=1;d[[n]]-=1;d=Select[d,#>0&];m=Length@d;If[n-m==2,Throw[False],n=m]]];d=={})&
```
If anyone is interested, I’ll describe the algorithm a little more.
[Try it online!](https://tio.run/##VYw9C8IwFAB3f4VQKAopmOoWXikIguAgVnAIbwjNsyk0KaRBh9LfXit@oHDDwcFZFQxZFepSjRWMCw2RcHAgVwWTR2KrQmnkxdQNSZdxpuFEN/IdFa0PUqPQUnLEBPjT3NugoIbKqbMoW8Uo7Geoxf4qXWIBUnY2vr3LnWo6QubAIk43gH5YxuPR1y7klew5m/@yHnD2bZv/lr4YcHwA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [R](https://www.r-project.org), ~~58~~ ~~51~~ 45 bytes
*Edit: -6 bytes thanks to pajonk*
```
\(x,`+`=sum)max(+x^0-1,x)<=all(x)*+x/2*!+x%%2
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGiNNulpSVpuhY3dWM0KnQStBNsi0tzNXMTKzS0K-IMdA11KjRtbBNzcjQqNLW0K_SNtBS1K1RVjaCafqRpGGpypWmYgIhkDUMdMNSE8Ax0DDRh4sZQlhGcBVWrg5Az0DHSMYKrMwLrTk4s0VDSRYCYPCW4dqhSEyRtxkgWIUQN4LJGcF1AlToI1SZwxyDrA5uM5CGQDigf4v8FCyA0AA)
Based on [xnor's comment](https://codegolf.stackexchange.com/questions/259143/is-it-a-valid-chemical#comment571503_259154) on [Command master's Python answer](https://codegolf.stackexchange.com/a/259154/95126): upvote that!
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
Uses [S. L. Hakimi's result](https://www.semanticscholar.org/paper/On-Realizability-of-a-Set-of-Integers-as-Degrees-of-Hakimi/83b1608fb33eef2467a53f6ccffed559df7408dc) as aired by [Command Master](https://codegolf.stackexchange.com/users/92727/command-master) in their excellent [Python answer](https://codegolf.stackexchange.com/a/259154/53748).
```
ẠȧSH_L’»ṀƲeŻ$
```
A monadic Link that accepts a list of non-negative integers and yields `1` if a molecule may be formed or `0` if not.
**[Try it online!](https://tio.run/##y0rNyan8///hrgUnlgd7xPs8aph5aPfDnQ3HNqUe3a3y////aGMdBQSKBQA "Jelly – Try It Online")**
### How?
```
ẠȧSH_L’»ṀƲeŻ$ - Link: non-empty list of non-negative integers, D
Ạ             - all (D)? -> 0 if any of D are zero
  S           - sum (D)
 ȧ            - (all?) logical AND (sum)
   H          - halve (that) - call this X
         Ʋ    - last four links as a monad - f(D):
     L        -   length (D)
      ’       -   decrement
        Ṁ     -   maximum (D)
       »      -   (length-1) maximum (maximum(D)) - call this Y
    _         - (X) subtract (Y)
            $ - last two links as a monad - f(Q=that)
           Ż  -   zero range (Q) -> list of integers = [0..floor(Q)] (empty if Q < 0)
          e   -   (Q) exists in (that)?
```
[Answer]
# JavaScript (ES6), 67 bytes
Based on the theorem [found by @CommandMaster](https://codegolf.stackexchange.com/a/259154/58563).
Returns `1` for falsy or `0` for truthy.
```
a=>a.some(v=>!(s+=v,k++,m>v?v:m=v)&a>'0',m=k=s=0)|2*k>s+3|s<m*2|s%2
```
[Try it online!](https://tio.run/##jU/BToUwELzzFfWgtI9KSuGktp70C7xVDhsEn0KpYZ9NTPh3BC2Bd3vJpLs7nelOP8EDVsPH1@m2d2/11KgJlIYUna2pV/qKYqI8b5OEW@0f/Z1Vnt2AjkXMrWoVKsFGeWg1JvmID/YgR7yWU@V6dF2ddu6dxuYZOvwpY3YfGWKykhNTLEfGScAyCU5EYPOlylA31R/yoJ2vZUnKKG3c8ATVkQJRmuz3NhQYm3dGZ2Fee/MyfJ@OW56wvwhvzm2@RVgpEXgZ1IvkH8G7z7jzFeuUnRlX4pIPTL8 "JavaScript (Node.js) – Try It Online")
[Answer]
# [Thunno](https://github.com/Thunno/Thunno) `D`, \$ 21 \log\_{256}(96) \approx \$ 17.29 bytes
```
XDS2%!>xS2/xMxL1-ZPpP
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72sJKM0Ly9_abSSi1LsgqWlJWm6FlsjXIKNVBXtKoKN9Ct8K3wMdaMCCgIgclAlC1ZGG-soGOkoGMZCBAA) or
[verify all test cases](https://ato.pxeger.com/run?1=m72sJKM0Ly9_abRSilLsEs_qVJelpSVpuhZbI1yCjVQV7SqCjfQrfCt8DHWjAgoCIHKLXaO8IawFN49GRxvG6ihEm4AIQx0FKALxDHQUDKCixiDaCEojVIGRcWwsV3Q0TJOJjgJQnRGIaYzQBxMygIobQVWDlEAQVC-ywUj6TGA8QxSNMIFYiG8A)
Based on [Command Master's answer](https://codegolf.stackexchange.com/a/259154/114446). Somehow passes all the test cases.
Outputs \$0\$ for falsy and \$1\$ for truthy.
#### Explanation
```
XDS2%!>xS2/xMxL1-ZPpP  # Implicit input
XD                     # Store input in x for later
  S2%!                 # Sum is even?
      >                # Is the input greater than this?
       xS2/            # Divide the sum by 2
           xM          # Push the maximum of x
             xL1-      # Get the length and decrement
                 ZP    # Pair together
                   pP  # Sum / 2 greater than or equal to both?
                       # Implicit output
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 16 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
OÉ›¦IO;IàIg<‚@«P
```
Port of [*@CommandMaster*'s Python answer](https://codegolf.stackexchange.com/a/259154/52210), so make sure to upvote him/her as well!
[Try it online](https://tio.run/##yy9OTMpM/f/f/3Dno4Zdh5Z5@lt7Hl7gmW7zqGGWw6HVAf//R5vomOgYQ2AsAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaXLf//DnY8adh1aVulvXXl4QWW6zaOGWQ6HVgf81/kfHW0YqxNtAsSGOmAIZBnoGID5xkDSCExC5XQgYgY6RrE6CtEQxSY6RiButDFUOYRnABYxAqsAyuhAZE3gxsDUgXVDrQWpgrFNdEzAulB5IFNiAQ).
**Explanation:**
```
O           # Get the sum of the (implicit) input-list
 É          # Pop and check whether it's odd (0 if even; 1 if odd)
  ›         # Check for each value in the (implicit) input-list whether it's larger
            # (so the sum is even and none are 0)
   ¦        # Remove the very first check (for edge-case input=[0])
IO          # Push the sum of the input-list again
  ;         # Halve it
        ‚   # Pair
   Ià       # the maximum of the input-list
     Ig<    # with the length-1 of the input-list
         @  # Check [sum/2>=max, sum/2>=length-1]
«           # Merge this pair to the earlier list of checks
 P          # Check if all are truthy by taking the product
            # (after which the result is output implicitly)
```
[Answer]
# [Arturo](https://arturo-lang.io), 52 bytes
```
$[a][s:∑a(0=s%2)∧(>=s/2max a)∧(-size a 2)<s/2]
```
Thanks to S. L. Hakimi for solving the problem back in 1962 and @CommandMaster for finding the solution and explaining the relevant bits so clearly.
[![running the above code on the test cases](https://i.stack.imgur.com/iltwm.gif)](https://i.stack.imgur.com/iltwm.gif)
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata) + `-e`, 13 bytes
```
∑2¦$ṁ±*$:#←c≥
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFNtJJurpKOgpJuqlLsgqWlJWm6FtsfdUw0OrRM5eHOxkMbtVSslB-1TUh-1Ll0SXFScjFUzYKbm6INY7miTYDYUEcBioAcAx0FA4iYMZAyglAIFWAEEwLp11EAqjECsozhOqACBhBBI4hCkDQEQXQhm4fQYwLjGCLrgvEhTgcA)
A port of [@Command Master's Python answer](https://codegolf.stackexchange.com/a/259154/9288).
The flag `-e` set the interpreter to `CheckExistence` mode, which prints `True` if the computation has any result, and `False` otherwise.
```
∑2¦$ṁ±*$:#←c≥
∑2¦              Divide the sum of the input by 2. Fail if the remainder is not zero.
   $ṁ±*          Multiply it by the sign of the minimum element of the input.
            ≥    Check if the result is greater than or equal to all items of the following list:
       $:#←c       Prepend the length minus 1 to the input
```
---
# [Nekomata](https://github.com/AlephAlpha/Nekomata) + `-e`, 18 bytes
```
ʷ{P↕1:Ð-:C0=+?}0U=
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFNtJJurpKOgpJuqlLsgqWlJWm6FttOba8OeNQ21dDq8ARdK2cDW237WoNQ2yXFScnFUCULbqZFG8ZyRZsAsaGOAhQBOQY6CgYQMWMgZQShoHImOgpAASMgyxguDRUwgAgaQRSCpCEoFmIdAA)
This is extremely slow and takes up a lot of memory.
The idea is to repeatedly delete one edge at a time, until the result equals to `[0]`.
```
ʷ{P↕1:Ð-:C0=+?}0U=
ʷ{            }       Repeat the following function until it fails:
  P                     Fails unless the result is all positive.
   ↕                    Non-deterministically permute the list.
    1:Ð-                Decrement the first two elements of the list.
        :C0=+?          Drop the first element of the list if it is zero.
               0U=    Check if the result is equal to [0].
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 17 bytes
Based on [Command Master's answer](https://codegolf.stackexchange.com/users/92727/command-master)
```
∑₂?sṫ$∑≤?∑½?L‹≥WA
```
```
∑₂?sṫ$∑≤?∑½?L‹≥WA
∑₂                  Is the sum of the list even?
  ?sṫ$∑≤            Sort list, swap and sum tail-removed part, is lesser than or equal?
        ?∑½?L‹≥     Is length of list - 1 greater than or equal to half of the sum
               WA   Wrap stack, all truthy?
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLiiJHigoI/c+G5qyTiiJHiiaQ/4oiRwr0/TOKAueKJpVdBIiwiIiwiWzMsIDMsIDIsIDEsIDFdIl0=)
[Answer]
# TI-Basic, 28 bytes
```
max(dim(Ans)-1,max(Ans))≤min(Ans>0).5sum(Ans)not(fPart(.5sum(Ans
```
Takes input in `Ans`. Uses the same method as in [Command Master's Python 3 answer](https://codegolf.stackexchange.com/a/259154).
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 67 bytes
```
Length@x-2<BitNot[Tr@x]~Mod~2*If[AllTrue[x,#>0&],1,0]*Tr@x/2>=Max@x
```
[Try it online!](https://tio.run/##dVBda8MgFH3Pr7hksIfWMWPz1DYl26AwWMce@iYyZDOLkDaQOHCE9q9nagw1@5CLXs85V@@5B65KceBKvvG@oPqVLbP@SRw/VJnrG7K@l@q5VnTf5Jqdd/X7mcweC3pXVfvmU1CNrjb4mqEEYTazmluyyXZc57p/aeRR0XjLq1Z8LWO2igqXPvBWtJBB1yUnBF1qtwSBD3vDCLBHF/Yk/ryoXIwcsfLTKtrWDZXmYUNJWGcwmKDBr8ww8zmCobWAoFQyQ8YQIyh@EWZFkbdjXKtysKNcGtjx7aeuJWLTxaRLB2GPE6@2kiF8bWgxqEvHWzIpDACjSMfH/sLcH//PKbAznVNATOf0kzCr/wY)
A port of [@Command Master's answer](https://codegolf.stackexchange.com/a/259154/9288).
Explicit Mathematica Code is
```
f[x_List] := Module[{len, bitNotSumMod, allPositive, halfSum, maxVal},
    len = Length[x] - 2;
    bitNotSumMod = BitNot[Total[x]] ~Mod~ 2;
    allPositive = If[AllTrue[x, # > 0 &], 1, 0];
    halfSum = Total[x] / 2;
    maxVal = Max[x];
    len < bitNotSumMod * allPositive * halfSum >= maxVal
]
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 20 bytes
```
¬∨﹪Σθ²‹∧⌊θΣθ⊗⌈⊞Ｏθ⊖Ｌθ
```
[Try it online!](https://tio.run/##LY3BCsIwDIZfxWOEeRFvngYeNzfwOHaoXbCFNnFpK759jbrwB374vhDrjFg2odZRPGW4coZBoOelBIZbibDum91Rt8OUoKUFek8@buAvaLlwuQdUaN4/OJbkhieKySywKkcrGJGyOh3SI7vv3TbnWqfppG8081wPr/AB "Charcoal – Try It Online") Link is to verbose version of code. Outputs a Charcoal boolean, i.e. `-` for a valid chemical, nothing if not. Explanation: Based on @CommandMaster's Python answer.
```
    θ                    Input list
   Σ                     Sum
  ﹪                      Modulo
     ²                   Literal integer `2`
 ∨                      Logical Or
         θ              Input list
        ⌊               Minimum
       ∧                Logical And
           θ            Input list
          Σ             Sum
      ‹                 Is less than
                   θ    Input list
                  Ｌ     Length
                 ⊖      Decremented
              ⊞Ｏ        Appended to
                θ       Input list
             ⌈          Maximum
            ⊗           Doubled
¬                       Logical Not
                        Implicitly print
```
* `len(x) - 2 < ~sum(x) % 2 * all(x) * sum(x) / 2 >= max(x)` becomes
* `~sum(x) % 2 * all(x) * sum(x) / 2 >= max(*x, len(x) - 1)` becomes
* `~sum(x) % 2 * all(x) * sum(x) >= 2 * max(*x, len(x) - 1)` becomes
* `not(~sum(x) % 2 * all(x) * sum(x) < 2 * max(*x, len(x) - 1))` becomes
* `not(sum(x) % 2 or all(x) * sum(x) < 2 * max(*x, len(x) - 1))` becomes
* `not(sum(x) % 2 or (min(x) and sum(x)) < 2 * max(*x, len(x) - 1))`.
]