Solve the attached problem in the C++ language The country of Hackerland can be represented as a
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The country of Hackerland can be represented as a tree of g_nodes numbered from 1 to g_nodes where the ith edge represents a road that connects the cities g_from[i] and g_to[i]. Suppose the maximum distance, i.e. the number of edges between any two cities, is mx. A city is primary if it lies on the simple path between two cities u and v such that the distance between u and vis equal to mx. All other cities are secondary. Find the sum of indices of all the secondary cities. Example g_nodes = 4 g_from=[1,1,2] g_to= [2, 3, 4] 2 4 1 3 The maximum distance between any two nodes is 3, the pair (3, 4). All the cities on the path 3 --> 1 -- > 2 --> 4 are primary. Since no city is secondary, the answer is 0. Function Description Complete the function getSecondaryCitySum in the editor below. getSecondaryCitySum has the following parameters: int g_nodes: number of nodes in the tree int g from/g edges]: one end of each edge The country of Hackerland can be represented as a tree of g_nodes numbered from 1 to g_nodes where the ith edge represents a road that connects the cities g_from[i] and g_to[i]. Suppose the maximum distance, i.e. the number of edges between any two cities, is mx. A city is primary if it lies on the simple path between two cities u and v such that the distance between u and vis equal to mx. All other cities are secondary. Find the sum of indices of all the secondary cities. Example g_nodes = 4 g_from=[1,1,2] g_to= [2, 3, 4] 2 4 1 3 The maximum distance between any two nodes is 3, the pair (3, 4). All the cities on the path 3 --> 1 -- > 2 --> 4 are primary. Since no city is secondary, the answer is 0. Function Description Complete the function getSecondaryCitySum in the editor below. getSecondaryCitySum has the following parameters: int g_nodes: number of nodes in the tree int g from/g edges]: one end of each edge The country of Hackerland can be represented as a tree of g_nodes numbered from 1 to g_nodes where the ith edge represents a road that connects the cities g_from[i] and g_to[i]. Suppose the maximum distance, i.e. the number of edges between any two cities, is mx. A city is primary if it lies on the simple path between two cities u and v such that the distance between u and vis equal to mx. All other cities are secondary. Find the sum of indices of all the secondary cities. Example g_nodes = 4 g_from=[1,1,2] g_to= [2, 3, 4] 2 4 1 3 The maximum distance between any two nodes is 3, the pair (3, 4). All the cities on the path 3 --> 1 -- > 2 --> 4 are primary. Since no city is secondary, the answer is 0. Function Description Complete the function getSecondaryCitySum in the editor below. getSecondaryCitySum has the following parameters: int g_nodes: number of nodes in the tree int g from/g edges]: one end of each edge
Expert Answer:
Answer rating: 100% (QA)
include include include using namespace std void dfsint node vector graph vector visited unordere... 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 accounting questions
-
answer all questions as instructed below. make sure you have attended all questions .Comparative Architectures (a) Describe the organisation of a two-level branch predictor that makes use of a global...
-
(a) Sets containing integers can be represented as int list values. Consider two such representations called unordered and ordered. In the former elements can appear in any order; in the latter...
-
A 100-m-long conductor of uniform cross section has a voltage drop of 4 V between its ends. If the density of the current flowing through it is 1.4 x 106 (A/m2), identify the material of the...
-
Bernie sells his house to Consuela under a warranty deed. Later, Delmira appears, holding a better title to the house than Consuela has. Delmira wants Consuela off the property. What can Consuela do?
-
Find the mole fractions of O present in equilibrium O 2 at 1000 K and at 5000 K. Assume P = 1 atm. Repeat the calculation for N 2 and the same conditions.
-
Continuing to focus on evidence associated with the act, concealment, and conversion, use the evidentiary material to continue the examination. In addition, as the examiner also start to think of...
-
The physicians in Problem 3-34 have been approached by a market research firm that offers to perform a study of the market at a fee of $5,000. The market researchers claim their experience enables...
-
Vanessa went to Florida and purchased a laptop for US$920.00 by converting his Canadian money at an exchange rate of C$1 = US$0.9254. After a month, he returned to Vancouver but the exchange rate...
-
Instructions You are expected to read the article titled: Risk mitigation in IT outsourcing strategy revisited: longitudinal case research at LISA, and answer the case study questions in the next...
-
What are three features of cost accounting and cost management that can be used for a wide range of applications? explain.
-
1. The following is a condensed market value balance sheet for Twitter: Total assets = $15,000,000 Total debt = Total equity = $6,000,000 $9,000,000 What is Twitters cost structure (i.e., percent...
-
SolBridge Inc. is all-equity-financed. The expected rate of return on the company's shares is 10%. Suppose the company issues debt, repurchases shares, and moves to a debt-to-equity ratio of 4...
-
Please refer to the topic references: What can you say about Risk and return? Importance of risk and return. Purpose of risk and return. Difference between risk and return. Introduction of the topic....
-
1. Suppose you can afford a $350 monthly car payment. How much can you afford to finance at 4.75% APR for 5 years? 2. You deposit $350 a month into an account earning an APR of 2.3% compounded...
-
Company is rated investment grade has 2 bonds with 5% coupon, trading 95% and mature in 7 years. Bonds are identical, expect one has a 102% change of control, other does not. the company should be a...
-
Determine how far a 10 kg block will travel along a 20-degree ramp if the coefficient of friction between the ramp and the block are s= 0.7, and k = 0.4 and the block has an initial velocity of 4m/s...
-
U.S. households have become smaller over the years. The following table from the 2010 GSS contains information on the number of people currently aged 18 years or older living in a respondent's...
-
Even when the economy is holding steady, the unemployment rate tends to fluctuate because of seasonal effects. For example, unemployment generally goes up in Quarter 3 (summer) as students (including...
-
Use the MIP branch-and-bound algorithm presented in Sec. 12.7 to solve the following MIP problem interactively: Maximize Z = 3x1 + 4x2 + 2x3 + x4 + 2x5, Subject to and xj ¥ 0, for j = 1, 2, 3, 4,...
-
The Audiofile Company produces boomboxes. However, management has decided to subcontract out the production of the speakers needed for the boomboxes. Three vendors are available to supply the...
-
James Madison, the fourth President of the United States, was 163 cm tall. His height converts to the z score of -2.28 when included among the heights of all presidents. Is his height above or below...
-
Which do you think has less variation: the IQ scores of students in your statistics class or the IQ scores of a simple random sample taken from the general population? Why?
-
Carbon monoxide is measured in San Francisco on five different days, and the mean of those five values is 0.62 parts per million. Four of the values (in parts per million) are 0.3, 0.4, 1.1, and 0.7....
Study smarter with the SolutionInn App