CHEFBR - DFS

My solution is here. I find all the bracket pairs first. Each pair is a node. The edges of nodes are constructed by checking whether two pairs are not overlapped or one is inside the other. Finally the DFS is applied to count.

I only passed half of the tests. What’s wrong with my code? What did I miss?