build a graph then bfs
tle