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

建议使用的浏览器:

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

4303:Hourai Jeweled

题目描述
Kaguya Houraisan was once a princess of the Lunarians, a race of people living on the Moon. She was exiled to Earth over a thousand years ago for the crime of using the forbidden Hourai Elixir to make herself immortal. Tales of her unearthly beauty led men from all across the land to seek her hand in marriage, but none could successfully complete her trial of the Five Impossible Requests.

One of these requests is to reckon the value of "Hourai Jeweled (蓬莱の玉の枝)". The only one real treasure Kaguya has, in her possession. As showed in the picture, Hourai Jeweled is a tree-shaped twig. In which, each node is ornamented with a valuable diamond and each edge is painted with a briliant color (only bright man can distinguish the difference). Due to lunarians' eccentric taste, the value of this treasure is calculated as all the gorgeous roads' value it has. The road between two different nodes is said to be gorgeous, if and only if all the adjacent edges in this road has diffenrent color. And the value of this road is the sum of all the nodes' through the road.
Given the value of each node and the color of each edge. Could you tell Kaguya the value of her Hourai Jeweled?
输入解释
The input consists of several test cases.
The first line of each case contains one integer N (1 <= N <= 300000), which is the number of nodes in Hourai Jeweled.
The second line contains N integers, the i-th of which is Vi (1 <= Vi <= 100000), the value of node i.
Each of the next N-1 lines contains three space-separated integer X, Y and Z (1<=X,Y<=N, 1 <= Z <= 100000), which represent that there is an edge between X and Y painted with colour Z.
输出解释
For each test case, output a line containing the value of Hourai Jeweled.
输入样例
6
6 2 3 7 1 4
1 2 1
1 3 2
1 4 3
2 5 1
2 6 2
输出样例
134
提示
gorgeous roads are :
1-2 		Value: 8
1-3 		Value: 9
1-4		Value:13
1-2-6   	Value:12
2-1-3         Value:11
2-1-4 	Value:15
2-5		Value:3
2-6 		Value:6
3-1-4	        Value:16
3-1-2-6 	Value:15
4-1-2-6 	Value:19
5-2-6		Value:7
来自杭电HDUOJ的附加信息
Author BUPT
Recommend zhuyuanchen520

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

源链接: HDU-4303

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

共提交 0

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