Question: Write simple python/java program and also explain the logic because i am crying so much and not able to understand. THE VALUE OF A WEIGHTED

Write simple python/java program and also explain the logic because i am crying so much and not able to understand.

THE VALUE OF A WEIGHTED TREE

You are given a weighted undirected tree with N nodes. Every edge has a weight associated with it.

You are required to find the value of (i=1 to N-1) (j=i+1 to N) F(i,j) function where F(i,j) denotes the sum of weights of edges on a simple path between node i and j.

Input format:

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains an integer N denoting the number of nodes in the tree.
  • Next N-1 lines contain three space-separated integers u v w denoting an edge between u and v with weight w.

Output format:

For each test case, print the value of function modulo 10^9 + 7 in a new line.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!