Help Me with my Solution

Why does my code fail on test case 3 ?
All elements of size[] are set to 1 initially so how can i get a sequence of zeroes ?
Here is the link to my solution-
https://codeforces.com/contest/1167/submission/54963224