↵
Что я придумал: попытаемся найти для корня границу разделения между поддеревом ребра веса $0$ и веса $1$. Можно заметить, что если $0$-ребро ведет влево, то граница — это `max(pos(0), pos(предпоследней_1))`, потому что в правом поддереве ровно $1$ единица. А если $0$-ребро ведет вправо, то граница — это
↵
Here is what I came up with: let's try to find the split boundary for the root between the subtree of the $0$-weight edge and the $1$-weight edge. We can notice that if the $0$-edge goes left, the boundary is `max(pos(0), pos(second_to_last_1))`, because there is exactly $1$ one in the right subtree. And if the $0$-edge goes right, the boundary is `min(pos(0), pos(
↵
↵
↵
[388357320](https://codeforces.me/contest/1919/submission/388361656)↵
↵



