Stores the rank ( depth ) of each node
rank = [ 1 ] * ( n * m ) NEW_LINE grid = [ 0 ] * ( n * m ) NEW_LINE for i in range ( len ( query ) ) : NEW_LINE INDENT x = query [ i ] [ 0 ] NEW_LINE y = query [ i ] [ 1 ] NEW_LINE DEDENT