[Question]
  [
### Input:
A matrix containing integers in the range **[0 - 9]**.
### Challenge:
Determine if all non-zero elements are connected to each other vertically and/or horizontally.
### Output:
A [truthy value](https://codegolf.meta.stackexchange.com/a/2194/31516) if all are connected, and a [falsy value](https://codegolf.meta.stackexchange.com/a/2194/31516) if there are non-zero elements/groups that aren't connected to other elements/groups.
### Test cases:
Test cases are separated by line. Test cases can be found in more convenient formats [here](https://tio.run/##TU9BEoIwDLzvK3JAB4FhqFAQeQbesEw9ePCgB/WmfssH@DFMAo5Mps1ms9mm1@P9dDkMnzcatL5psAhDzkNPEToEcNjfYiSE82rr0xhdsHSIdr5z/vGCSyhFQ@jTpwswtD4YMiAjvgxxCBwLSX/KYOyMoTgny23BIl6ryCjO@S5RKSeVaDZclXzqmY8VUxn6vT45sxtmCk5MmNEOlg3XPGWpEgRt5JPakFUsa9fKFSquSUL4YtpXP/gF) ([Kudos to Dada](https://codegolf.stackexchange.com/a/129148/31516)).
The following are all connected and should return a truthy value:
```
0
--- 
0 0
---
1 1 1
0 0 0
---
1 0 0
1 1 1
0 0 1
---
0 0 0 0 0 0
0 0 3 5 1 0
0 1 0 2 0 1
1 1 0 3 1 6
7 2 0 0 3 0
0 8 2 6 2 9
0 0 0 0 0 5
```
The following are all not-connected, and should return a falsy value:
```
0 1
1 0
---
1 1 1 0
0 0 0 2
0 0 0 5
---
0 0 5 2
1 2 0 0
5 3 2 1
5 7 3 2
---
1 2 3 0 0 5
1 5 3 0 1 1
9 0 0 4 2 1
9 9 9 0 1 4
0 1 0 1 0 0
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest submission in each language wins. **Explanations are encouraged!**
---
Inspired by [this challenge](https://codegolf.stackexchange.com/q/154306/31516).
  
[Answer]
# [MATL](https://github.com/lmendo/MATL), 7 bytes
```
4&1ZI2<
```
This gives a matrix containing all ones as [truthy](https://codegolf.stackexchange.com/a/95057/36398) output, or a matrix containing at least a zero as [falsy](https://codegolf.stackexchange.com/a/95057/36398). [Try it online!](https://tio.run/##y00syfn/30TNMMrTyOb//2gDBTi0BlPGCqYKhhAOkFIwAtHWQKYhWM5QwcxawRwsCuKClVkAuWZAbGmtgDBMwTQWAA)
You can also verify truthiness/falsiness adding an `if`-`else` branch at the footer; [try it too!](https://tio.run/##y00syfn/30TNMMrTyOa/vQIcqCp4pnGplxSVlmRUqoP5AaXFGQolGZnFCsUlRZl56Vy1yKpdc4pTudTTEnOKwcqxqP8fbaAAh9ZgyljBVMEQwgFSCkYg2hrINATLGSqYWSuYg0VBXLAyCyDXDIgtrRUQhimYxgIA)
Or [verify all test cases](https://tio.run/##bU@xjsIwDN3zFV6gW9WUFqiCxAIDGwPToUpUupZGCi0iQYiBby@2c4VWuliJ/Z6fHftSONOd4HMmsGnDMHzU2pRdMpU/u3jVrYf5XSUCd7u7@hkw3t9tDa7WFqy76eYsXkP11thSBFVhLMv/0@cjffMLuhKb0UTaXk3x/MPiMJqmqXSjXQk8MZi2vXbHKBfHCOiVgKYggh6iVzBgpZf25skZpKhgQBUxeV9FOQlzBQtmCbJsiXCON1PwbQYpN@fSzzD9H9hWjWToiZK@sUI0w1BSsKCQG8T0IUlJmDLgVTJmE1@QsVEm6VfgxfM3).
### Explanation
```
4       % Push 4 (defines neighbourhood)
&       % Alternative input/output specification for next function
1ZI     % bwlabeln with 2 input arguments: first is a matrix (implicit input),
        % second is a number (4). Nonzeros in the matrix are interpreted as
        % "active" pixels. The function gives a matrix of the same size
        % containing positive integer labels for the connected components in 
        % the input, considering 4-connectedness
2<      % Is each entry less than 2? (That would mean there is only one
        % connected component). Implicit display
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~80~~ ~~77~~ 74 bytes
```
T`d`@1
1`1
_
+m`^((.)*)(1|_)( |.*¶(?<-2>.)*(?(2)$))(?!\3)[1_]
$1_$4_
^\D+$
```
[Try it online!](https://tio.run/##K0otycxL/P8/JCElwcGQyzDBkCueSzs3IU5DQ09TS1PDsCZeU0OhRk/r0DYNextdIzugqIa9hpGmiqamhr1ijLFmtGF8LJeKYbyKSTxXXIyLtsr//4YKRgrGCgZAaMplqGAKZhsqGHJZgsVMgLIgNgiCxE24QCQEGwAA "Retina 0.8.2 – Try It Online") Edit: Saved 1 byte thanks to @FryAmTheEggman. Explanation:
```
T`d`@1
```
Simplify to an array of `@`s and `1`s.
```
1`1
_
```
Change one `1` to a `_`.
```
+m`^((.)*)(1|_)( |.*¶(?<-2>.)*(?(2)$))(?!\3)[1_]
$1_$4_
```
Flood fill from the `_` to adjacent `1`s.
```
^\D+$
```
Test whether there are any `1`s left.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 54 bytes
Saved 2 bytes thanks to user202729.
```
Max@MorphologicalComponents[#,CornerNeighbors->1<0]<2&
```
[Try it online!](https://tio.run/##RY7LCoMwEEX3/Qqh0FUKjq9WsKXg2tK9uEhLfIAmErMoiN@eTkaxDJPh3LnczMBNKwZuug@3tXfzbMG/j0LpsVW9alDtczWMSgpppvLIcqWl0E/RNe1b6el8h8yvsuBkX7qTpqzLefbZXgsjClnMYCOcLMAGJCAK8U2QLqQ7Xp1X5AQ73VLWipelqg7/3wAd4bZxiTERUH5KeoSOlVy5XbRfAnQlJtof "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# JavaScript (ES6), ~~136~~ 135 bytes
Returns a boolean.
```
m=>!/[1-9]/.test((g=(y,x=0)=>1/(n=(m[y]||0)[x])&&!z|n?(m[y++][x]=0,z=n)?g(y,x)&g(--y-1,x)&g(y,x+1)||g(y,x-1):g(m[y]?y:+!++x,x):m)(z=0))
```
### Test cases
```
let f =
m=>!/[1-9]/.test((g=(y,x=0)=>1/(n=(m[y]||0)[x])&&!z|n?(m[y++][x]=0,z=n)?g(y,x)&g(--y-1,x)&g(y,x+1)||g(y,x-1):g(m[y]?y:+!++x,x):m)(z=0))
console.log('[Truthy]')
console.log(f([
  [0]
]))
console.log(f([
  [0,0]
]))
console.log(f([
  [1,1,1],
  [0,0,0]
]))
console.log(f([
  [1,0,0],
  [1,1,1],
  [0,0,1]
]))
console.log(f([
  [0,0,0,0,0,0],
  [0,0,3,5,1,0],
  [0,1,0,2,0,1],
  [1,1,0,3,1,6],
  [7,2,0,0,3,0],
  [0,8,2,6,2,9],
  [0,0,0,0,0,5]
]))
console.log('[Falsy]')
console.log(f([
  [0,1],
  [1,0]
]))
console.log(f([
  [1,1,1,0],
  [0,0,0,2],
  [0,0,0,5]
]))
console.log(f([
  [0,0,5,2],
  [1,2,0,0],
  [5,3,2,1],
  [5,7,3,2]
]))
console.log(f([
  [1,2,3,0,0,5],
  [1,5,3,0,1,1],
  [9,0,0,4,2,1],
  [9,9,9,0,1,4],
  [0,1,0,1,0,0]
]))
```
### Commented
The recursive function **g()** first looks for a non-zero cell (as long as the globally-defined flag **z** is set to **0**) and then starts flood-filling from there (as soon as **z != 0**).
```
m =>                               // given the input matrix m
  !/[1-9]/.test((                  // test whether there's still a non-zero digit
    g = (y, x = 0) =>              //   after recursive calls to g(), starting at (x=0,y=0):
      1 / (n = (m[y] || 0)[x]) &&  //     n = current cell; if it is defined:
      !z | n ? (                   //       if z is zero or n is non-zero:
          m[y++][x] = 0,           //         we set the current cell to zero
          z = n                    //         we set z to the current cell
        ) ?                        //         if z is non-zero:
          g(y, x) &                //           flood-fill towards bottom
          g(--y - 1, x) &          //           flood-fill towards top
          g(y, x + 1) ||           //           flood-fill towards right
          g(y, x - 1)              //           flood-fill towards left
        :                          //         else:
          g(m[y] ? y : +!++x, x)   //           look for a non-zero cell to start from
      :                            //       else:
        m                          //         return the matrix
    )(z = 0)                       //   initial call to g() + initialization of z
  )                                // end of test()
```
[Answer]
# C, 163 bytes
*Thanks to @user202729 for saving two bytes!*
```
*A,N,M;g(j){j>=0&j<N*M&&A[j]?A[j]=0,g(j+N),g(j%N?j-1:0),g(j-N),g(++j%N?j:0):0;}f(a,r,c)int*a;{A=a;N=c;M=r;for(c=r=a=0;c<N*M;A[c++]&&++r)A[c]&&!a++&&g(c);return!r;}
```
Loops through the matrix until it finds the first non-zero element. Then stops looping for a while and recursively sets every non-zero element connected to the found element to zero. Then loops through the rest of the matrix checking if every element is now zero.
[Try it online!](https://tio.run/##hVPdboIwFL73KToTCbU1AQQUu87wAPICzgvSiZFkbOnYFeHZWX9A56AdOcF6fr7zna8Htrow1nXLFGf4QC5uCZvyhXpO@ZwtD46THsvTXr6oh0UQZVD@LLJ9ufJ3nvqzUj6ElFf4dh5pCzfHHDN4replTpqU5iSjjBwoJ8UHdxnlNKceYbIJSY8MoZPjIMShOIvTU46Q41xcBgk/19@8euKk7QQYeM@vlQtnzQyIRzrq81ftH0@AgsZriXJ/chEo3Pni7bWaY1C4KgcDaRCS2UNt0NdiYC0PVHkwKl/rchGTCFjF/jx958mYKgK@rfMaA2mjzuGt8z/o1rlCMdQUenSX5cHMbQTJSHExJmmRAj2yRSoNJg7xZNJmwNB5xnZblRerd2LTZ7DIJpSYTTSOR0LFN6GMI1kvQPMbL9bm8Xqt0itVrWHraBulYziisP29A5Gph3@/jqlwpMADkzxaVplhYyiuMpximNxECvpd0FQNPKMhyfjFJANGaOGc4N40Umjfd9/wEYrhQD9eoqip3Wq7Hw)
**Unrolled:**
```
*A, N, M;
g(j)
{
    j>=0 & j<N*M && A[j] ? A[j]=0, g(j+N), g(j%N ? j-1 : 0), g(j-N), g(++j%N ? j : 0) : 0;
}
f(a, r, c) int*a;
{
    A = a;
    N = c;
    M = r;
    for (c=r=a=0; c<N*M; A[c++] && ++r)
        A[c] && !a++ && g(c);
    return !r;
}
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~36~~ 22 bytes[SBCS](https://github.com/abrudz/SBCS)
```
~0∊∨.∧⍨⍣≡2>+/|↑∘.-⍨⍸×⎕
```
[Try it online!](https://tio.run/##TVDBCsIwDL33K3pckela181d/JeBTARhXgXxOKsw0YPoVTwofoF3/yQ/MpOUzRFK897LS9Lmq2U4W@fLct7A8bIooTpFAtyuaLYRuAO41xDcE@oX1A/Y3810MNpAdQZ3G4bMfr5XNDZoaQoB9TsSdO0pk5xX50BLDBUgISPVcQT6km4lrvPhlbG0WMaAbIaL2UqalokKUmYJctkEYYInU71uVomwG8ENetvodgKFaRPb38kSr/0gFVicZaiNlSml/1aGtmAzAsuAH5kxG3tXJilIidt3@S8R4Q8 "APL (Dyalog Unicode) – Try It Online")
thanks @H.PWiz
`⍸×⎕` coordinates of non-zero squares
`2>+/|↑∘.-⍨` [adjacency matrix](https://en.wikipedia.org/wiki/Adjacency_matrix) of the neighbour graph
`∨.∧⍨⍣≡` [transitive closure](https://en.wikipedia.org/wiki/Transitive_closure)
`~0∊` is it all 1s?
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 23 bytes
```
FJṁa@µ«Ḋoµ€ZUµ4¡ÐLFQL<3
```
[Try it online!](https://tio.run/##y0rNyan8/9/N6@HOxkSHQ1sPrX64oyv/0NZHTWuiQg9tNTm08PAEH7dAHxvj/4fbgYL//0dzRUcbxMbqgCgdBSjLUEcBhGJ1FMCCyOJgDlAcQ4khwhBkhFBgrKNgCtYEE4OYZgTVDTcTohTIMAOJmcNUQIRhei3AwmZg0hLJnTBkCncNzGRUr6G4DOQKFJ4psl9MobKGcJeAeKZg5xhBzQfyzCECcFuMIO6FmgfRbwoTgwWdJUyFCcIsoBgEQdSZoIQWLAZiuWIB "Jelly – Try It Online")
---
## Explanation.
The program labels each morphological components with a different numbers, then check if there are less than 3 numbers. (including `0`).
Consider a row in the matrix.
```
«Ḋo   Given [1,2,3,0,3,2,1], return [1,2,3,0,2,1,1].
«     Minimize this list (element-wise) and...
 Ḋ      its dequeue. (remove the first element)
      So min([**1**,**2**,3,**0**,3,2,**1**],
             [2,3,**0**,3,**2**,**1**]    (deque)
      ) =    [1,2,0,0,2,1,1].
  o   Logical or - if the current value is 0, get the value in the input.
         [**1**,**2**,0,0,**2**,**1**,**1**] (value)
      or [1,2,**3**,**0**,3,2,1] (input)
      =  [1,2,3,0,2,1,1]
```
Repeatedly apply this function for all row and columns in the matrix, in all orders, eventually all morphological components will have the same label.
```
µ«Ḋoµ€ZUµ4¡ÐL  Given a matrix with all distinct elements (except 0),
               label two nonzero numbers the same if and only if they are in
               the same morphological component.
µ«Ḋoµ          Apply the function above...
     €           for **€**ach row in the matrix.
      Z        **Z**ip, transpose the matrix.
       U       **U**pend, reverse all rows in the matrix.
               Together, **ZU** rotates the matrix 90° clockwise.
         4¡    Repeat 4 times. (after rotating 90° 4 times the matrix is in the
               original orientation)
           ÐL  Repeat until fixed.
```
And finally...
```
FJṁa@ ... FQL<3   Main link.
F                 **F**latten.
 J                Indices. Get `[1,2,3,4,...]`
  ṁ               **ṁ**old (reshape) the array of indices to have the same
                  shape as the input.
   a@             Logical AND, with the order swapped. The zeroes in the input
                  mask out the array of indices.
      ...         Do whatever I described above.
          F       **F**latten again.
           Q      uni**Q**ue the list.
            L     the list of unique elements have **L**ength...
             <3   less than 3.
```
[Answer]
# [Haskell](https://www.haskell.org/), 132 bytes
```
 \m->null.snd.until(null.fst)(\(f,e)->partition(\(b,p)->any(==1)[(b-d)^2+(p-q)^2|(d,q)<-f])e).splitAt 1.filter((/=0).(m!)).indices$m
```
extracted from [Solve Hitori Puzzles](https://codegolf.stackexchange.com/questions/154306/solve-hitori-puzzles/154734#154734)
`indices m` lists the `(line,cell)` locations of the input grid.
`filter((/=0).(m!))` filters out all locations with non-zero values.
`splitAt 1` partitions off the first member into a singleton list next to a rest list.
`any(==1)[(b-d)^2+(p-q)^2|(d,q)<-f]` tells if `(b,p)` touches the frontier `f`.
`\(f,e)->partition(\(b,p)->touches(b,p)f)e` splits off touchers from not[yet]touchers.
`until(null.fst)advanceFrontier` repeats this until the frontier can advance no further.
`null.snd` looks at the result whether all locations to be reached were indeed reached.
[Try it online!](https://tio.run/##ZU5BbsMgELz7FVTKYVfFNCS1k0hxpEg99geOK5HaVlGBECCHSP27C/iSqkLszszC7HwJ/z0oNUltLy6QNxEEOzon7sWj8i59KLSQprFOmrDQwsJETro8mJtSzJue3UyQCjIdfUA4wUgHLA9WuCCDvJionKmNijB3aBqOLZzLHj9Wz2DLa@w/0NMr7suxwwGZt0qGYyCcjVKFwQG8NEtkoJ8QmTS9/Bz8Qk@kVTFbTgzAKUcKG1ojtkv696xpRXlGqa5y5xmvY63pJmuJpbqNrI539@BQdbQghPzbV@V9PL6e/6Y9VcbJf3Z4jdOEd5nzyOccOVHXTb8 "Haskell – Try It Online")
[Answer]
# Perl, ~~80~~ ~~79~~ ~~78~~ ~~73~~ 70 bytes
Includes `+2` for `0a`
Give the input matrix without spaces on STDIN (or in fact as rows separated by any kind of whitespace)
```
perl -0aE 's%.%$".join"",map chop,@F%seg;s%\b}|/%z%;y%w-z,-9%v-~/%?redo:say!/}/'
000000
003510
010201
110316
720030
082629
000005
^D
```
Easier to read if put in a file:
```
#!/usr/bin/perl -0a
use 5.10.0;
s%.%$".join"",map chop,@F%seg;s%\b}|/%z%;y%w-z,-9%v-~/%?redo:say!/}/
```
[Answer]
# [Grime](https://github.com/iatorm/grime), 37 bytes
```
C=[,0]&<e/\0{/e\0*0$e|CoF^0oX
e`C|:\0
```
Prints `1` for match and `0` for no match.
[Try it online!](https://tio.run/##Sy/KzE39/9/ZNlrHIFbNJlU/xqBaPzXGQMtAJbXGOd8tziA/gis1wbnGKsbg/38DMOAyMDA2NQRShgZGBoZchoYGxoZmXOZGQGGgoIWRmZElF1ihKQA "Grime – Try It Online")
## Explanation
The nonterminal `C` matches any nonzero character that is connected to the first nonzero character of the matrix in the English reading order.
```
C=[,0]&<e/\0{/e\0*0$e|CoF^0oX
C=                             A rectangle R matches C if
  [,0]                         it is a single character other than 0
      &                        and
       <                       it is contained in a rectangle S which matches this pattern:
        e/\0{/e\0*0$e           R is the first nonzero character in the matrix:
        e                        S has an edge of the matrix over its top row,
         /0{/                    below that a rectangle of 0s, below that
             e\0*0$e             a row containing an edge, then any number of 0s,
                                 then R (the unescaped 0), then anything, then an edge.
                    |CoF^0oX    or R is next to another match of C:
                     CoF         S is a match of C (with fixed orientation)
                        ^0       followed by R,
                          oX     possibly rotated by any multiple of 90 dergees.
```
Some explanation: `e` matches a rectangle of zero width or height that's part of the edge of the input matrix, and `$` is a "wildcard" that matches anything.
The expression `e/\0{/e\0*0$e` can be visualized as follows:
```
+-e-e-e-e-e-e-e-+
|               |
|      \0{      |
|               |
+-----+-+-------+
e \0* |0|   $   e
+-----+-+-------+
```
The expression `CoX^0oX` is actually parsed as `((CoF)0)oX`; the `oF` and `oX` are postfix operators and concatenation of tokens means horizontal concatenation.
The `^` gives juxtaposition a higher precedence then `oX`, so the rotation is applied to the entire sub-expression.
The `oF` corrects the orientation of `C` after it is rotated by `oX`; otherwise it could match the first nonzero coordinate in a rotated English reading order.
```
e`C|:\0
e`       Match entire input against pattern:
    :    a grid whose cells match
  C      C
   |     or
     \0  literal 0.
```
This means that all nonzero characters must be connected to the first one.
The grid specifier `:` is technically a postfix operator, but `C|:\0` is syntactic sugar for `(C|\0):`.
[Answer]
# Java 8, ~~226~~ ~~219~~ ~~207~~ ~~205~~ 201 bytes
```
int[][]M;m->{int c=0,l=m[0].length,i=m.length*l;for(M=m;i-->0;)c+=m[i/l][i%l]>0?f(i/l,i%l):0;return c<2;}int f(int x,int y){try{M[x][y]*=M[x][y]>0?f(x+f(x,y+f(x-f(x,y-1),y)),y)-1:1;}finally{return 1;}}
```
-2 bytes thanks to *@ceilingcat*.
[Try it online.](https://tio.run/##pVPBcpswEL3nK/aSGYgFBicktSnuLTfnktwYDjIRsVIhMiBSMwzf7qxk0oCbaaZlNMLap923u0/rZ/pKnefHn4dU0KqCDeUS2jMALhUrM5oyuNMmwLYoBKMSUguv4iROcjvEiw730V1jmxDmc5gtYdsoVoEqQO2YMZy0qKVCzzuQEMEhd9YtBkEaeUREeewlrmDySe0Ij/L@eCHCrCitTZSH3HHWXminM3Tlc5HE/Fwka@9HZqFF0LBXXlgyVZdY4fdF2IWaPNO1wp7ob2O3qmzaTbxP4ia5iPqD4djPcJNGfx1zcnybNLbejr/ywy7jkgrRtH0GRLoDwEu9FTyFSlGFP68Ff4Qc9bPuVcnlU5wAtY/aGVVzbFuyX8awjHagxXooa7VrVsa8byrFcreolfuCFEpIK3elm1o6rpf4yAjQep05dXbP9W/BZFK4T3B1ZMA2lU8TkL/Q@xO7fV9j1ksSYKoRqEtZmISjcrSvT64/wBvjpeFR@DeEr3EvT9QxK/i6if7mfTpuqajYf03HuIHpr30qHap0CgRT3ygYcvpHgT@AALVeDNsKyI2GprW20C9oih9kDgw4GsKl8boaV7AkemnPq9MZ8qf@Jz4d2U@eok/2hdcfXP5vaFhjd9Yd3gA)
**Explanation:**
```
int[][]M;              // Integer-matrix on class-level, uninitialized
m->{                   // Method with integer-matrix parameter & boolean return
  int c=0,             //  Amount of non-zero islands, starting at 0
      l=m[0].length,   //  Amount of columns in the matrix
      i=m.length*l;    //  Index integer
  for(M=m;             //  Set the class-level matrix to the input
      i-->0;)          //  Loop over the cells
    c+=                //   Increase the count by:
       m[i/l][i%l]>0?  //    If the current cell is not 0:
        f(i/l,i%l)     //     Flood-fill the matrix with a separated method
                       //     And increase the count by 1
       :               //    Else:
        0;             //     Leave the count the same
  return c<2;}         //  Return whether 0 or 1 islands are found
// Separated recursive method with cell input & integer return
int f(int x,int y){
  try{m[x][y]*=M[x][y]>0?
                       //  If the current cell is not 0:
           f(m,x,y-1)  //   Recursive call west
          f(m,x-...,y) //   Recursive call north
         f(m,x,y+...)  //   Recursive call east
        f(m,x+...,y)   //   Recursive call south
        -1:1;}         //   Empty the current cell
  }finally{            //  Catch and swallow any ArrayIndexOutOfBoundsExceptions
                       //  (shorter than manual if-checks)
           return 1;}  //  Always result in 1, so we use it to our advantage
                       //  to save bytes here by nesting, instead of having four
                       //  loose calls to each direction)
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~211~~ ~~163~~ 150 bytes
```
m,w=input()
def f(i):a=m[i];m[i]=0;[f(x)for x in(i+1,i-1,i+w,i-w)if(x>=0==(i/w-x/w)*(i%w-x%w))*a*m[x:]]
f(m.index((filter(abs,m)or[0])[0]))<any(m)<1>q
```
[Try it online!](https://tio.run/##bVBNc4IwEL3zK3accUwUKxGhFcWbPbaX3hgOqGHMVD4a4wC/noZEaFo7s9mv93bzkrIR5yJftsfiRMPRaNRmdhWyvLwJhK0TTSFFDAdJmEUs3nQudDZRimqcFhxqYDliM2KzuTyzSsYKM4nuQicMEVtU83pR4SliY5mNK4ynyTSL6iCOrRRlTyw/0RqhlF0E5Sg5XO0MFzxyYtwdvE3yBmV4S3ZfrZRmVWd2ofDBbzSwAARvugBAa3qETr@qSs5yAZM0uVybidWhR1oKeEsyuue84IHJEvwmziZt//5qsA6cJp@t1GIDsSLHhi5bWhGRtTJHm@y6qqvrPzDRsDPQf5trg2eylV8@LHJV4tvw3KO6qZMX1fSVXz9c4UkFvlJwX/f/M4ybf@ZWvXJPYcRgeEqAbnpKWFfqGc1zDSrpBwYZg9BVv2Xdm@asjB8hw1f73w "Python 2 – Try It Online")
Output is via exit code. Input is as an 1d list and the width of the matrix.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~115~~ 102 bytes
```
A=>w=>(A.find(F=(u,i)=>u&&[-w,-1,1,w].map(v=>v*v>1|i%w+v>=0&i%w+v<w&&F(A[v+=i],v),A[i]=0)),!+A.join``)
```
[Try it online!](https://tio.run/##VVDdbsIgGL3nKdjFGpgUi1qd2SDpxbzcC3RN6LRVTG1NrdQY370DWjeXL8D5DuccfvapTk/rWh0bv6w2WZfzLuKi5QJFNFflBq04OhOFuTh7Xuy3xGeEkTahh/SINBf6RQt2U8/tSAseeA68t563QlGsR1wlRGMSxSrhAcbkaRTRfaVKKXH3BnRaw4bLAPi@DwLYrwyast1vb9Efy@7qezk8haFRWGz1E6djDk/NPAcLx9nOal5NNzdj@ZATDrnW93CTId9kgv86gwzH@lwQmuSJ8YZwYdHgn9jznIfB0GH7iqXjZk6/hLYsPxvu7t4r6elYqEa6HOn@@sJFfOlpNIa3r3K8xW7j83z4zmpMLnePjINkwFDSIiu3zS7BoKF5VX@k6x26crGuylNVZLSotihHV@PAZmYJxrj7AQ "JavaScript (Node.js) – Try It Online")
Receive input as `(1d-array)(width)`. Rewrites all entries in one of the connected non-zero regions with 0 and checks whether the resultant array is a zero matrix. The matrix will become zero if there is zero or one connected non-zero region.
```
A=>                         // all rows are concatenated into an 1-d array
 w=>                        // width of the original matrix
  (
   A.find(                  // find the first non-zero entry
    F=(                     // helper function
     u,                     // value of the entry
     i                      // index of the entry
    )=>
     u                      // return 0 if value is 0 or out of range
     &&[-w,-1,1,w].map(     // return an array otherwise, and find the neighbors
      v=>                   // for each neighbor
       v*v>1                // if y-coord change: let go anyway
       |i%w+v>=0&i%w+v<w    // if x-coord change: let go only if on the same row
       &&F(A[v+=i],v),      // recurse on the neighbor
      A[i]=0                // before recursing change the current entry to 0
     )
   ),                       // if all entries were 0, no change is made
   !+A.join``               // return whether all entries are now 0
  )                         // if all entries are 0, then +A.join`` == 0
```
> 
> **Tip:** Use `Array.prototype.find` if you want to map through an array with a function that the return values can be ignored but to stop once the function is executed.
> 
> 
> In this case, I want to map through the array to change only the first connected non-zero region found, but not the other regions (otherwise the array will become a zero matrix no matter what the original input is), so `find` is used here to save some bytes.
> 
> 
> 
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 96 bytes
```
f=(A,P,Q)=>!A.map((B,i)=>B.map((C,j)=>(P-i)**2+(Q-j)**2-1|!C||f(A,i,j,A[i][j]=0,P=0+[P])))|P>'0'
```
[Try it online!](https://tio.run/##VVBRb4IwGHzvr6hPFm0RUHRkKQmavS74zExgDBwExQAjxvDf2fcVnC5fgLvr3dE2j9qojqvs0ohz@ZX0fSqZx32@16Q78fRTdGFsyzNg24HseA6E@SLTZjNrzvYiRyDMbrLruhTCGc@5F2SHID9Ig/vSmAf@QdO0znenxrR/JW1U0UaGBhFCEIMOX5PCIPvjiB6qeXffR@EltcGBGP2W8pkKL@G9JhulIUPPC7A1PM5Tjz32Yu5pJ2M/dJL/PkCgmUMvsaHZgqxNN4jGvIX/UxmT2grjKRylrZTfoTior8a9q/OGen0psiZUPaG68Kt0r4PKFh/nxVFTaivddvTSwff@c/pMKrhm0uhpWb1F8Te7STcuz3VZJHpRHlnKbrDe/wI "JavaScript (Node.js) – Try It Online")
`P` = `0` if 1 chunk, `00` if 2 chunk, to allow call inside
[Answer]
# [Uiua](https://www.uiua.org/), 31 bytes
```
/×♭⍥'∺'/↥↧.⧻.⊠(≤1/+⌵-).▽♭∶/⊂⇡△.
```
[Try it online!](https://www.uiua.org/pad?src=ZiDihpAgL8OX4pmt4o2lJ-KIuicv4oal4oanLuKnuy7iiqAo4omkMS8r4oy1LSku4pa94pmt4oi2L-KKguKHoeKWsy4KZiBbWzIgMyAwXSBbMSAwIDBdXQpmIFtbMSAxIDBdIFsxIDAgMV1dCmYgW1swIDBdXQ==)
The same approach as [ngn's APL answer](https://codegolf.stackexchange.com/a/154407/78410).
```
∧↧1♭⍥'∺'/↥↧.⧻.⊠(≤1/+⌵-).▽♭∶/⊂⇡△.    input: a matrix(n,m)
▽♭∶/⊂⇡△.  collect coordinates of positive numbers:
       ⇡△     coordinates of each position in the matrix (n,m,2)
     /⊂       reduce by join; flatten the first two dimensions
  ♭∶      .    original matrix flattened
▽             keep: for each number n in the matrix, get n copies of its coords
⊠(≤1/+⌵-).  create adjacency matrix:
⊠(      ).    self cross product over the coordinates:
   ≤1/+⌵-      sum of absolute difference is 1 or less?
⍥'∺'/↥↧.⧻.  get transitive closure:
⍥       ⧻.    run <length of the array> times:
  '∺'/↥↧.      self matrix product, using min as product and max as sum
/×♭         test if it is all ones
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 42 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Ā©˜ƶ®gäΔ2Fø0δ.ø}2Fø€ü3}®*εεÅsyøÅs«à]˜0KÙg!
```
Input as a matrix of integers; output as a 05AB1E truthy/falsey value (only \$1\$ is truthy in 05AB1E, so if the result is \$\geq2\$ it's falsey).
[Try it online](https://tio.run/##yy9OTMpM/f//SMOhlafnHNt2aF364SXnphi5Hd5hcG6L3uEdtSDmo6Y1h/cY1x5ap3Vu67mth1uLKw/vAJKHVh9eEHt6joH34Znpiv//R0cb6MBhrA6YZ6xjqmMI5QFpHSMgNgTyDME8YyBpBuSZg8VBfIhKCyDfDIgtoaZAoGlsLAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V@mFFCUWlJSqVtQlJlXkpqikJlXUFpipaCkU3lotw6XkmNySWliDlzUvvLQSlsuJf/SEihf6f@RhkMrT885tu3QuvTDS85NMXI7vMPg3Ba9wztqQcxHTWsO7zGuPbRO69zWc1sPtxZXHt4BJA@tPrwg9vQcA@/DM9MV/yvphbnYZyopaJQUlZZkVGoqHV4N5KQl5hSnAjm1Ooe22f@Pjo42iI3VUQBSOlCGoQ4QxuqABBBCIKYOipQhXBsMQiWMdUyByiA8kEYjsGKIZpCsoY4ZkGcOFgfxISotgHwzILaE2QyGpjBLIAYguxBuH9AGOMsU4ShTsLAhxBogyxRolRHYHFMdcxAbZpYRyA1gvSDlpmAexJuWYHETqDZLHRAEyZnA/QYJmNhYAA).
**Explanation:**
Uses the same flood-fill algorithm I've used in multiple other challenges.
```
Ā             # Convert each positive integer in the (implicit) input-list to 1s
 ©            # Store this matrix in variable `®` (without popping)
  ˜           # Flatten it to a single list
   ƶ          # Multiply each by its 1-based index to make all values unique
    ®gä       # Convert it back to a matrix with the dimensions of `®`
Δ             # Loop until it no longer changes to flood-fill:
 2Fø0δ.ø}     #  Add a border of 0s around the matrix:
 2F     }     #   Loop 2 times:
   ø          #    Zip/transpose; swapping rows/columns
     δ        #    Map over each row:
    0 .ø      #     Add a leading/trailing 0
 2Fø€ü3}      #  Convert it into overlapping 3x3 blocks: 
 2F    }      #   Loop 2 times again:
   ø          #    Zip/transpose; swapping rows/columns
    €         #    Map over each inner list:
     ü3       #     Convert it to a list of overlapping triplets
 ®*           #  Multiply each 3x3 block by the value in matrix `®`
              #  (so the 0s remain 0s)
 εεÅsyøÅs«à   #  Get the largest value from the horizontal/vertical cross of each 3x3
              #   block:
 εε           #   Nested map over each 3x3 block:
   Ås         #     Pop and push its middle row
     y        #     Push the 3x3 block again
      ø       #     Zip/transpose; swapping rows/columns
       Ås     #     Pop and push its middle rows as well (the middle column)
         «    #     Merge the middle row and column together to a single list
          à   #     Pop and push its maximum
]             # Close the nested maps, flood-fill loop, and outer loop
 ˜            # Flatten the resulting flood-filled matrix
  0K          # Remove all 0s
    Ù         # Uniquify the values of each island
     g        # Pop and push its length (which is 1 if it was a single island)
      !       # Factorial to convert 0 to 1 (and 1 remains 1), since 0 is also truthy
              # (after which the result is output implicitly)
```
[Answer]
# [Perl 5](https://www.perl.org/), ~~131~~ 129 + 2 (`-ap`) = 133 bytes
```
push@a,[@F,0]}{push@a,[(0)x@F];$\=1;map{//;for$j(0..$#F){$b+=$a[$'][$j+$_]+$a[$'+$_][$j]for-1,1;$\*=$b||!$a[$'][$j];$b=0}}0..@a-2
```
[Try it online!](https://tio.run/##PUzbCoJAFHz3KzY6kOZt1/RBZGGf9idsiRWKkspFCwL119vOGsUwnJk5w5hjfy2sNc/hLHRUCxlRNY8/69PgJaSqYM9ZddNmTNPq1PXQ@jRJYC2DEZqQg65ho2poQziocHFOYaCwHLOI4cCWQzNNq38XRxtO5xmHhI4zaxlhZEcoovAYKRaNmVfiLUlOskU7uGbuue@X9N2Zx6W7DzbW5gM "Perl 5 – Try It Online")
]