Where is your BFS stop clause?
Your main loop should break
once you find x == t1 && y == t2
Alternatively, you can modify parent[v]
only if visited[v]
was already true.
(The first option is usually better if you just want the shortest path).
Otherwise, you'll just keep developing more paths, and override the shortest path to each node.