Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started