Question: Could someone help to solve it in Java 8 2. Cost of the Transaction Imagine that you are building an electrical grid for a group
Could someone help to solve it in Java 8


2. Cost of the Transaction Imagine that you are building an electrical grid for a group of settlements on Mars. As with every grid, it has a central power switching station located in the biggest/central settlement, and it has smaller settlements around it. Each smaller settlement has its own power switching station, and they are all interconnected. Let's say there are N settlements on Mars that are uniquely numbered between [1...N]. The central power switching station is represented with 1. The power between switching stations can be transferred in either direction and it is guaranteed that there will be exactly one path between two stations. This means that there will be N -1 connections which will be used to connect the stations. As we know from physics, each station also has a power loss parameter measured in Martian Watt(MW) (number in red), that shows exactly how much power will be lost on every transfer. Electricity will be transferred between two power stations if the power loss is equal to what is projected by the engineers as we want to be sure that we have a precisely planned electrical grid. Otherwise, the power transfer operation cannot be initiated. 5 0.32 11 0.2 4 0.28 6 017 10 0.3 12 1 0.05 03 2 02 7 0.4 3 0.8 9 0.1 8 0.36 The diagram above represents a sample martian electrical grid, and as we can see #1 node is the central power switching station. Examples of how we calculate power loss between stations: Power loss for transferring electricity between stations #3 and #2 is 0.2 +0.8 = 1MW Power loss for transferring electricity between stations #8 and #10 is equal to the sum of power losses on the path between those two stations, which means that the power needs to be transferred through settlement8 # settlement7 settlementi settlement10 accumulating to 0.36 +0.4+0.3 +0.3 = 1.36 MW Sample Configuration Input: First, you will receive the information about the Martian power grid, with the first line containing integer N that denotes the number of power stations in the grid, excluding the central power grid, followed by N lines of comma-separated integers u, v explaining that U is directly connected to V in the power grid (e.g. like #9 is connected to #7 in the example above). Immediately followed by N +1 lines Zrepresenting a power loss in each node. It is important to note that power switching station numbers start with 1 and are incremented by 1. 11 1,2 2,3 (1,4 4,5 4,6 1,10 10, 11 10,12 1,7 7,8 7,9 0.3 0.2 0.8 0.28 0.32 0.17 0.4 0.36 0.1 0.3 0.2 0.05 Constraints: 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
