Stores the rank ( depth ) of each node
int [ ] rank = new int [ n * m ] ; for ( int i = 0 ; i < rank . Length ; i ++ ) rank [ i ] = 1 ; bool [ ] grid = new bool [ n * m ] ; for ( int i = 0 ; i < query . GetLength ( 0 ) ; i ++ ) { int x = query [ i , 0 ] ; int y = query [ i , 1 ] ;