当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6241:Color a Tree

题目描述
Bob intends to color the nodes of a tree with a pen. The tree consists of $N$ nodes. These nodes are numbered $1, 2, ..., N$. The root of the tree is node $1$. The initial color of each node is white. Bob can use one unit energy to color one node into black. To prevent Bob being lazy with painting, Alice proposed $A + B$ rules. Each rule is represent by two numbers $x_i$ and $y_i$.
For the first $A$ rules, it means that there should be no less than $y_i$ nodes painted black for the subtree of node $x_i$.
For the other $B$ rules, it means that there should be no less than $y_i$ nodes painted black for all nodes except the subtree of node $x_i$.
You need to help Bob to calculate the minimum energy he needs for the painting with all rules proposed by Alice satisfied.
输入解释
The first line is the number of test cases. For each test case, the first line contains one positive number $N(1 \leq N \leq 100000)$, indicating the number of trees nodes.

The following $N - 1$ lines describe the edges. Each line contains two integers $u, v$($1 \leq u, v \leq N$), denoting there is a edge between node $u$ and node $v$.

The following one line contains one number $A$($A \leq 100000$), indicating the first $A$ rules.

The following $A$ lines describe the first $A$ rules. Each line contains two numbers $x_i$ and $y_i$ as described above.

The following one line contains one number $B$($B \leq 100000$), indicating the other $B$ rules.

The following $B$ lines describe the other $B$ rules. Each line contains two numbers $x_i$ and $y_i$ as described above.
输出解释
For each test case, output a integer donating the minimum energy Bob needs to use with all rules propose by Alice satisfied. If there is no solution, output $-1$ instead.
输入样例
2 
5
1 2
2 3
3 4
1 5
2
2 1
5 1
1
2 1
5
1 2
2 3
3 4
1 5
3
1 2
2 2
5 1
1
3 5
输出样例
2
-1
来自杭电HDUOJ的附加信息
Recommend jiangzijing2015

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6241

最后修改于 2020-10-25T23:29:36+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 262144/262144K(Java/Others)