2d bfs kernel of calculating gini score