You can watch the questions here.It was one of the questions in our school question bank and I tried to solve it, but unluckily that I didn't know how. Can you help me find the official solution to this problem (or this contest)? Thank you!
Sorry, my English isn't very good.:<
I don't know how to do this question, but I think it will use dsu on tree.