Help needed in a codeforces problem

I cannot find bug in the solution.
Can somebody please help?
Problem link:here
Solution link:here
Test case where it fails:

1 4 4 1 3 3 1 2 2 4
6 8
10 7
8 1
9 4
7 2
4 2
6 10
3 10
10 2
6 3
8 2
7 5
9 10
9 5
1 4
6 7
6 4
5 8
7 4
10 1```
Expected correct answer:
```2 2 3 2 2 2 2 2 2 2```

@everule1

Your BFS is wrong.

1 Like

Yaa i actually spotted my mistake and did correct that.
Is there option to delete the post?
BTW Thanks