Rosalind第64题:Newick Format with Edge Weights

Problem

In a weighted tree, each edge is assigned a (usually positive) number, called its weight. The distance between two nodes in a weighted tree becomes the sum of the weights along the unique path connecting the nodes.

To generalize Newick format to the case of a weighted tree , during our repeated "key step," if leaves  are neighbors in , and all these leaves are incident to , then we replace  with , where  is now the weight on the edge .

Given: A collection of  weighted trees () in Newick format, with each tree containing at most 200 nodes; each tree  is followed by a pair of nodes  and  in .

Return: A collection of  numbers, for which the th number represents the distance between  and  in .

加权树中,每个边都分配有一个(通常为正)编号,称为其权重。加权树中两个节点之间的距离成为沿着连接节点的唯一路径的权重之和。

Newick格式概括为加权树的情况,在我们重复的“关键步骤”中,如果离开 有邻居在,所有这些叶子都入射到,那么我们替换  与 ,在哪里  现在是边缘上的重量 。

鉴于:的集合 加权树()以Newick格式,每棵树最多包含200个节点;每棵树 其次是一对节点  和  在 。

返回:的集合 数字,为此 th代表之间的距离  和  在 。

Sample Dataset

(dog:42,cat:33);
cat dog

((dog:4,cat:3):74,robot:98,elephant:58);
dog elephant

Sample Output

75 136
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值