Pku2054 Color a Tree

时间限制:1s      空间限制:64MB

题目描述


输入格式

The input consists of several test cases. The first line of each case contains two integers N and R (1 <= 1="" n="" <="1000," where="" is="" the="" number="" of="" nodes="" in="" tree="" and="" r="" node="" root="" node.="" second="" line="" contains="" integers,="" i-th="" which="" ci="" (1="" coloring="" cost="" factor="" i.="" each="" next="" n-1="" lines="" two="" space-separated="" numbers="" v1="" v2,="" are="" endpoints="" an="" edge="" tree,="" denoting="" that="" father="" v2.="" no="" will="" be="" listed="" twice,="" all="" edges="" listed.="" a="" test="" case="" indicates="" end="" input,="" should="" not="" processed.="" p="">


输出格式

For each test case, output a line containing the minimum total coloring cost required for Bob to color all the nodes.


样例输入

5 1
1 2 1 2 4
1 2
1 3
2 4
3 5
0 0


样例输出

33

提示

没有写明提示


题目来源

没有写明来源

Menuappsclose