Help required

I can’t seem to understand where my solution is wrong :frowning:

Can anyone tell me why my submission is giving WA.
link :https://atcoder.jp/contests/abc146/submissions/9849641

It would be great if someone can tell where it is wrong or provide a case where it fails.

Thanks for your time :slight_smile:

Consider case-

4
1 2
3 4
1 4

Correct Ouput: -

2
1
1
2

Your output:

2
0
1
2
1 Like

Thanks a lot !