Atcoder abc 174

Hello,
In this problem: https://atcoder.jp/contests/abc176/tasks/abc176_d

Why do we use deque?
Also , When do we push_front and when push_back?

Thanks

Deque is used for BFS. Alternatively, you can use LinkedList.