See these two files:
https://www.dropbox.com/s/8zap7yuhwdb0p ... .capx?dl=0
https://www.dropbox.com/s/r1em8npglbdso ... e.png?dl=0
(I downloaded them from some old post, which unfortunately I can't find now)
This example may look different from what you need, but it basically does the same task - connects occupied tiles on the tilemap to each other.
So if you have two tiles, one at (0,0) and another at (0,1), you need for the first one to select the tile with exit on the bottom, and for the second tile - with entrance on the top. And so on..
You can do all this with an array instead of the tilemap.