Remove cells based on cell path

Hello all
I have a square grid if I want to delete the specified cells based on the cell path (tree data).
Note The number of networks must be even. Glad to help.