faster bfs, code g++ 4.9 friendly
merged