[Question]
  [
This challenge is based off of Flow Free. An online version can be found here: <http://www.moh97.us/>
You will be given a puzzle, and you must return `1` if the puzzle is solvable, or `0` if it is not.
To solve a puzzle, the player must create a path to connect each pair of numbers using every empty square exactly once.
You are passed in the dimensions of the square, and then the x,y,c (where c is a number representing the color) of each dot. For example:
If `5,5` `0,0,0` `3,0,1` `1,1,2` `1,2,2` `4,2,1` `4,4,0` was passed to you, it would represent:
```
0..1.
.2...
.2..1
....0
```
And should return 1.
---
Here are some more test problems:
`5,2` `2,0,1` `0,1,2` `4,1,2` represents:
```
..1..
2...2
```
and is not solvable because there is only 1 `1`.
`4,2` `0,0,0` `3,0,0` `0,1,0` `3,1,0` represents:
```
0..0
0..0
```
and is not solvable because it includes more than 2 `0`s.
`8,6` `0,0,1` `7,5,1` represents:
```
1.......
........
........
........
........
.......1
```
and is not solvable (as you can't use every square).
`2,5` `0,0,1` `2,0,6` `4,0,6` `0,1,4` `3,1,4` `4,1,1` represents:
```
1.6.6
4..41
```
and is not solvable because you cannot connect the 1s.
`6,3` `1,0,4` `5,0,1` `0,1,4` `1,1,3` `5,1,3` `0,2,2` `3,2,2` `5,2,1` represents:
```
.4...1
43...3
2..2.1
```
and is not solvable because you cannot connect the 1s (or the 3s), as the two paths must necessarily cross.
`5,2` `0,0,1` `3,0,1` `0,1,3` `4,1,1` represents:
```
1..1.
3...3
```
and is not solvable because you cannot use all of the squares in building a path.
`2,2` `0,0,0` `1,1,0` represents:
```
1.
.1
```
and is not solvable because you can't use all of the squares here either
Here are some more tests:
`5,5` `0,3,0` `0,4,1` `1,2,2` `1,3,1` `2,0,0` `3,0,4` `3,1,2` `3,3,5` `3,4,4` `4,4,5` should return 1
`13,13` `1,1,0` `9,1,1` `10,1,2` `11,1,3` `1,2,4` `2,2,5` `5,2,6` `7,2,7` `3,3,0` `5,4,6` `6,4,1` `9,6,3` `4,7,8` `5,8,9` `12,8,8` `11,9,10` `2,10,4` `4,10,2` `9,10,5` `11,10,7` `1,11,9` `12,12,10` should return 1
`7,7` `0,0,0` `0,1,1` `1,1,2` `2,1,3` `4,2,4` `0,3,1` `5,3,3` `0,4,4` `2,4,5` `5,4,2` `0,5,0` `1,5,5` `3,5,6` `3,7,6` should return 0
---
This is a code golf, and the standard rules apply.
  
[Answer]
## Haskell
```
import Data.List.Split
import qualified Data.Sequence as Q
import Data.List
import Control.Monad
data A a = S a | E a | P a | X deriving Eq
sc = foldr1 (Q.><)
sp b x y p = Q.update y (Q.update x p $ b `Q.index` y) b
dt b c | S c `elem` sc b = E c
       | otherwise = S c
ad b [x, y, c] = sp b x y (dt b c)
ep b [x, y, c] = do
  let nps = filter ob [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]
      ns = map gp nps
  [b | E c `elem` ns] ++ do
    (x', y') <- filter ((== X) . gp) nps
    ep (sp b x' y' (P c)) [x', y', c]
  where ob (u, v) = 0 <= u && u < length (b `Q.index` 0) && 0 <= v && v < length b
        gp (u, v) = b `Q.index` v `Q.index` u
rd i = let [c, r] : ps = (map read . splitOn ",") <$> words i :: [[Int]]
           e = Q.replicate r $ Q.replicate c X
           cs = map last ps
           ss = nubBy (\[_,_,c1] [_,_,c2] -> c1 == c2) ps
           b = foldl ad e ps
           bs = foldM ep b ss
       in if even (length cs) && length ss == length cs `div` 2 &&
             (all (\[j,k] -> j==k) . chunksOf 2 . sort $ cs) &&
             any (null . Q.elemIndicesL X . sc) bs
           then 1
           else 0
main = rd <$> getContents >>= print
```
### Key
* sc: Seq concat
* sp: set position
* dt: dot type (ie, start or end of line)
* ad: add dot
* ep: extend path
* rd: run dots (primary pure algorithm)
[Answer]
# Python3, 538 bytes:
```
R=range
def f(x,y,v):
 d={}
 for j in R(x):
  for k in R(y):d[r]=d.get(r:=v.get((j,k),-1),[])+[(j,k)]
 if any(i!=-1 and len(d[i])!=2 for i in d):return 0
 D=eval(str(d));del D[(M:=max(d))][0]
 q=[(M,D,d[M][0],0)]
 while q:
  M,D,(j,k),C=q.pop(0)
  if(j,k)in D[M]:
   Y=eval(str(D));del Y[M]
   if(M:=max(Y))!=-1:q+=[(M,Y,Y[M][0],0)];del Y[M][0]
   if{-1:[]}==Y:return 1
   continue
  for J,K in[(-1,0),(1,0),(0,1),(0,-1)]:
   if(T:=(j+J,k+K))in D[-1]:Y=eval(str(D));Y[-1].remove(T);q+=[(M,Y,T,C+1)]
   elif T in D[M]and C:q+=[(M,D,T,C+1)]
```
[Try it online!](https://tio.run/##fVRdT@pAEH2@/RVrfGBXBrLbbQvU9EmeNL4YXkjT3IAtWsUCpXo1xt/OnZktaC7khmZazpw5c2b6sf5oHleVHa7r3e4uqWfVQ@HlxUIs5Dt8wJuKPZEnn1@eWKxq8STKStzJd0IZeHbAh4rztM6SvP9QNLKOkze@kE/wrKBnFKSZ6qb8N/NEuRCz6kOWZ0nP4FUulkUl87TM1Fnis2xJsrmK66J5rSuhPTFOirfZUm6bWuZKXebFUoxTeRsnL7N3QrJUo/ImQQzGkKe3BICmdn8ey2UhNmSZcs7UVbLpr1drqRXC5YJB7DnGQiKK6Xe/cdtvijlKIbvtO1WKZog3Xe47hel330MJG6OqT2Sm2VeSTPdzGUrcr6qmrF6LdqPXcIPDp7JnUAWkixoMR1yls4ceJnEin7rX8Ny9Uc56z2TxP76nBPbr4mX1VsiJujw4ncBV1yh2VizxhkxEOz3dj6v9ROM9b7c1IhGdEEKhAX/CYjTCgAEfo48xwGgwBqA73tZ3dF/4TNRMDChi0lIS@T@0NFPo2nB9QJQhREwxYgAhGIRDgv3WhWHxCGU1Ew0EXB9wI6JHRI/AokWNcHjwErB1iwhFzQNYjiGNgaWD/QCukz2U2oP60JnZj2Fa66PvTVmeK@BN@bwp27p2Uzu/1Noi3yIz4A2GKGM06RgkWCctRtRXGLdL4wYg3QAVaSdkPcJV@TBgRY1IgEjEDkYQsfcBDBEfwkgYH09DUkJljSJGu93hPqiZRk1qo1EPT8aV0EFjGn4iBpjTh/u3fyL8dk/kTfPMIUbLuyC3Abt1T0DIqwt5/hDdWnQYdfgb1Kx@l9VabvFz82sG4mKOHbf97XpZNlJ5v9q3qKwaOWvRDnRUajIFR6BGUHxKwudtWqmYzveK3jvUn4O4p9cgLX8UHj5H8@zL87x1TSULebH3ZpRSx6h/ErWEnh/BAcKiKV@KrVi9Nsdl4Umx6CQ6OIkOT6Kj03aMJj/n/zFkaOjdXw)
]