设为首页 加入收藏

TOP

small tree
2015-07-20 17:42:35 来源: 作者: 【 】 浏览:1
Tags:small tree

Problem Description

There is a rooted tree which has N nodes numbered form 0 to N-1.Root is labeled 0.Each edge connects two nodes with a weight. Your job is to find S, a set of nodes {s1, s2…. sm} (0<=m a) Root is not in S, which means,0 b) There is only one common ancestor between si and sj, which means, they have no common ancestor except root.
c) There are two associate set W, {w1,w2….wm}, and D, {d1,d2….dm},wi is the sum of weights of the path from root to si, di is the edge numbers of the path from root to si. The average outcome of S = ∑wi / ∑di (1<=i<=m) is maximal.

Input

There is a number T in the first line which is the number of test cases.
Each case begins with a integer n (2<=n<=1000), the number of nodes of the tree
Next n-1 lines each contains three integers i, j, k, indicating there is a directed edge from i to j with weight k.

Output

Output a floating point number for each case, which is the maximum average weight of S. Exact to 0.01.

Sample Input

3

1

2

0 1 2

3

0 1 1

0 2 2

Sample Output

0.00

2.00

2.00

Hint

If your got a WA, maybe it's an accuracy error and you should plus your answer with an 1e-10

//题意是求每条边到根节点的权值除以经过的路径 的条数的最大值,则只要用邻接矩阵求最大值就好了。

#include
  
   
#include
   
     int n,map[1010][1010]; double len; void dfs(int nd,int edge,double weight) { if(len
     
     


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Palindrome Partitioning 下一篇浅谈C++ Lambda 表达式(简称LB)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·工业机器人TCP校准中 (2025-12-25 05:19:17)
·opc 通讯协议与 TCP (2025-12-25 05:19:15)
·labview中tcp/ip通信 (2025-12-25 05:19:13)
·新书介绍《Python数 (2025-12-25 04:49:47)
·怎么利用 Python 进 (2025-12-25 04:49:45)