ARC083E. Bichrome Tree

A viable configuration of the given tree can be divided into two trees, each consists of vertices of the same color (if we compress edges and add a dummy root node when needed). Let's call them TB and TW, respectively. Note that TB and TW are independent of each other with respect to satisfying the conditions. For each vertex u in TA, it must hold that the total weight of u's proper descendants is no more than Xu, and in that case it is always possible make the total weight of vertices in subtree u be Xu by setting u's weight appropriately. The same can be said for TB. Ideally, we can configure the given tree such that in each subtree u, the total weight of vertices with a different color than u are minimized.

Official editorial:

The hard part of this problem is to understand the highlighted sentence.

code


I find this editorial in Chinese helpful.

posted @   Pat  阅读(150)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示