You are given an undirected graph consisting of N vertices, numbered from 1 to N, and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
You are given an undirected graph consisting of N vertices, numbered from 1 to N, and M edges. The graph is described by two arrays, A and B, both of length M. A pair (A[K], B[K]), for K from 0 to M-1, describes an edge between vertex A[K] and vertex B[K]. Your task is to assign all values from the range [1.N] to the vertices of the graph, giving one number to each of the vertices. Do it in such a way that the sum over all edges of the values at the edges' endpoints is maximal. For example, given N = 5, A = [2, 2, 1, 2], B = [1, 3, 4, 4], the graph has four edges: (2, 1), (2, 3), (1, 4), (2, 4). In order to obtain the maximum sum of weights, you can assign the following values to the vertices: 3, 5, 2, 4, 1 (to vertices 1, 2, 3, 4, 5 respectively). 5, val=1 1, val=3 7 2, val=5 3, val=2 9. 4, val=4 This way we obtain the sum of values at all edges' endpoints equal to 7 + 8 + 7 +9 = 31: This way we obtain the sum of values at all edges' endpoints equal to 7 + 8+7+9 = 31: edge (2, 3): 7 = 5 (vertex 2) + 2 (vertex 3) edge (2, 1): 8 = 5 (vertex 2) + 3 (vertex 1) edge (1, 4): 7 = 3 (vertex 1) + 4 (vertex 4) edge (2, 4): 9 = 5 (vertex 2) + 4 (vertex 4) Notice that the value assigned to vertex 5 did not have any effect on the final result as it is not an endpoint of any edge. Write a function: You are given an undirected graph consisting of N vertices, numbered from 1 to N, and M edges. The graph is described by two arrays, A and B, both of length M. A pair (A[K], B[K]), for K from 0 to M-1, describes an edge between vertex A[K] and vertex B[K]. Your task is to assign all values from the range [1.N] to the vertices of the graph, giving one number to each of the vertices. Do it in such a way that the sum over all edges of the values at the edges' endpoints is maximal. For example, given N = 5, A = [2, 2, 1, 2], B = [1, 3, 4, 4], the graph has four edges: (2, 1), (2, 3), (1, 4), (2, 4). In order to obtain the maximum sum of weights, you can assign the following values to the vertices: 3, 5, 2, 4, 1 (to vertices 1, 2, 3, 4, 5 respectively). 5, val=1 1, val=3 7 2, val=5 3, val=2 9. 4, val=4 This way we obtain the sum of values at all edges' endpoints equal to 7 + 8 + 7 +9 = 31: This way we obtain the sum of values at all edges' endpoints equal to 7 + 8+7+9 = 31: edge (2, 3): 7 = 5 (vertex 2) + 2 (vertex 3) edge (2, 1): 8 = 5 (vertex 2) + 3 (vertex 1) edge (1, 4): 7 = 3 (vertex 1) + 4 (vertex 4) edge (2, 4): 9 = 5 (vertex 2) + 4 (vertex 4) Notice that the value assigned to vertex 5 did not have any effect on the final result as it is not an endpoint of any edge. Write a function:
Expert Answer:
Answer rating: 100% (QA)
Java Code public class Main public static void mainS... View the full answer
Related Book For
Introduction to Operations Research
ISBN: 978-1259162985
10th edition
Authors: Frederick S. Hillier, Gerald J. Lieberman
Posted Date:
Students also viewed these programming questions
-
You are given an annual time series with 40 consecutive values and asked to fit a fifth-order autoregressive model. a. How many comparisons are lost in developing the autoregressive model? b. How...
-
You are given an M/M/1 queueing system with mean arrival rate and mean service rate . An arriving customer receives n dollars if n customers are already in the system. Determine the expected cost in...
-
You are given an M/M/2 queueing system with = 4 per hour and = 6 per hour. Determine the probability that an arriving customer will wait more than 30 minutes in the queue, given that at least 2...
-
A 2-in dia. steel bar is subjected to the loading indicated. Locate and estimate the maximum shear stress in the weld throat. F T____ 2 ...... kips 15 kip ·in 6 in in 2-in dia.
-
Sometimes changes in stock prices are recorded as percentages, other times as returns. The difference is a factor of 100: Percentage changes are 100 times the returns. How does this choice affect the...
-
Vernal Equinox wishes to borrow $10,000 for three years. A group of individuals agrees to lend him this amount if he contracts to pay them $16,000 at the end of the three years. What is the implicit...
-
What makes indirect benefits so difficult to include in a CBA? What techniques might be used?
-
Following is a traditional income statement for Mouse Max, a company that manufactures cordless mice for computers. Revenue ................................... $2,500,000 Cost of goods sold...
-
In the past, 30% of a country club's members brought guests to play golf sometime during the year. Last year, the club initiated a new program designed to encourage members to bring more guests to...
-
ALei Industries has credit sales of $150 million a year. ALeis management reviewed its credit policy and decided that it wants to maintain an average collection period of 40 days. a. What is the...
-
As a data analyst for an internal fraud advisory team at a regional accounting firm, you have been asked to perform a review of the fraud risk in the client's expense reimbursement process. You must...
-
For a single-phase, two-wire line consisting of two solid cylindrical conductors of same radius, \(r\), the total circuit inductance, also called loop inductance, is given by (in \(\mathrm{H} /...
-
Design a cosine-modulated filter bank with \(M=5\) sub-bands and at least \(40 \mathrm{~dB}\) of stopband attenuation.
-
Two small, irregularly shaped conducting objects, one carrying charge \(+q\) and one carrying charge \(-q\), are placed on an \(x\) axis at \(x=-4.0 \mathrm{~m}\) and \(x=+4.0 \mathrm{~m}\),...
-
Mr Chai has been trading for some years as a wine merchant. The following list of balances has been extracted from his ledger as at 30 April 2010, the end of his most recent financial year. The...
-
Resistor Ltd manufactures electrical units. All units are identical. The following information relates to June and July Year 5. (a) Budgeted costs and selling prices were: (b) Actual production and...
-
Security of tenure (appointment for life) is a pre-condition of judicial independence. While judges are appointed for life, those who work for administrative tribunals are not. Some have argued that...
-
In exchange for land, the company received a 12-month note on January 1. The face amount of the note is $1,000, and the stated rate of interest is 13%, compounded annually. The 13% rate is equal to...
-
Reconsider the example of a traveling salesman problem shown in Fig. 14.4. (a) When the sub-tour reversal algorithm was applied to this problem in Sec. 14.1, the first iteration resulted in a tie for...
-
Reconsider Prob. 20.4-6 involving the game of craps. Now the objective is to estimate the probability of winning a play of this game. If the probability is greater than 0.5, you will want to go to...
-
Reconsider Prob. 19.2-6. (a) Formulate a linear programming model for finding an optimal policy.
-
We may use Eq. (11.16) to generate sample paths of the generalized Wiener process by Monte Carlo sampling. We rewrite the equation for a small time step , and express the increment of the Wiener...
-
Consider a set of \(m\) assets, whose prices are modeled by stochastic processes , described by stochastic differential equations like (11.18). Let us assume that we pursue a portfolio strategy...
-
In order to apply It's lemma to the computation of the stochastic integral Data From Eq. (11.32) Data From Eq. (11.30) T W+dWt,
Study smarter with the SolutionInn App