Data structures assignment requiring c++ program

Assignment Help Data Structure & Algorithms
Reference no: EM1331546

Description: A long time ago in a galaxy far, far away, the country Mafghanistan had n cities and m old roads, where each road connected a pair of cities. Due to the treacherous mountains, there was no road or even path between some cities (i.e., some cities were unreachable from others). During Operation Mafghanistan Freedom, which spread democracy across Mafghanistan like wildfire in Santa Barbara in the summer, the Mamerican forces evaporated all the old roads in Mafghanistan. As the Commanding General of the Mamerican forces, you are in charge of Operation Mafghan Reconstruction, which will build new roads in Mafghanistan subject to the following constraints:

    Due to the treacherous mountains, you may build new roads only between the cities where old roads existed before Operation Mafghanistan Freedom.

    You should build enough new roads such that if City A was reachable from City B via some old roads, City A must be reachable from City B via some new roads.

    You should minimize the total lengths of the new roads to be built.

Define a region to be a set of cities that will be reachable from one another via some new roads. Find all the regions using algorithms with good asymptotic running times.

You may NOT use STL classes except the string class.

Input

Read input from cin. The input contains the number of cities (n), the number of old roads (m), and a series of old roads where each road is represented by its two terminal cities and its length. Each city is represented by a unique integer from 0 to n-1. Each road length is represented by an integer. The following EBNF specifies the input. An example input is available in the hand out. Your program need not handle invalid input (such as invalid file format or invalid numbers representing cities).

<input> ::= <num-cities> <num-old-roads> <old-road>*

<num-cities> ::= <ws>* <number> <ws>* '\n'

<num-old-roads> ::= <ws>* <number> <ws>* '\n'

<old-road> ::= <ws>* <city> <ws>+ <city> <ws>+ <length> <ws>* '\n'

<city> ::= <number>

<length> ::= <number>

<number> ::= <digit>+

<digit> ::= '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'

<ws> ::= ' ' | '\t'

Output

    On the first line, print

    <?xml version="1.5"?>

    On the second line, print:

    <country>

    Print each region in the ascending order of the number of cities in the region. For each region:

        On the first line, print:

        <region>

        Then, print each new road per line in the ascending order of the lengths of the roads. For each new road, print its two terminal cities represented by their numbers (print the smaller number before the larger number), and then the length of the road, as in the following example:

        <road>0 5 10</road>

        On the last line, print:

        </region>

    On the last line, print:

    </country>

The output of your program must match the output of the reference program. In other words, if you run

diff my_output your_output

you should see no output from diff.

Your program must exit with the exit code 0, i.e., call return 0 from the function main() or call exit(0).

Determinism in comparison of equal values

To avoid non-determinism of your algorithm when two roads e1=(s1, t1) and e2=(s2, t2) have the same length, consider e1 to be shorter than e2 if and only if

 

    min(s1, t1) < min(s2, t2), or

    min(s1, t1) == min(s2, t2) and max(s1, t1) < max(s2, t2)

To avoid non-determinism of your algorithm when two regions r1={...} and r2={...} have the same number of cities, consider r1 to have fewer cities than r2 if and only if min(r1) < min(r2), wheremin(s) returns the smallest member of the set s. Note that regions are disjoint sets of cities.

Resource limit

The gradebot has to limit resources, such as CPU time and memory, that each program can consume. If a program exceeds its resource limit, the gradebot will kill it, but the gradebot cannot distinguish between this case and other problems in the program (such as segmentation fault).

To test if a program exceeds the resource limit imposed by the gradebot, run:

bash -c 'ulimit -c 0 -d 500000 -f 100000 -m 100000 -n 50 -s 50000 -t 90 -v 500000; spantree < input_file > output_file'

 

When the program exceeds the resource limit, you will see the message Killed.

To learn more about resource limit, run man bash and skip to the section on ulimit (by typing /ulimit followed by a RETURN).

Hints

You probably need to implement union-find, min heap, minimum cost spanning tree, and an O(n log n) sorting algorithm (e.g., Quick Sort, in Section 7.3 of the textbook).

To optimize your program, run g++ with the -O3 option.

Reference no: EM1331546

Questions Cloud

Identify that a risk averse agent offered terms worse : Identify that a risk averse agent offered terms worse than actuarially fair will not choose to insure fully.
Explain ebusiness- legal and ethical and regulatory issues : What, if any, are the dysfunctional aspects of the "New Economy" promoted by e-Business? Identify any legal, ethical, regulatory and social issues that might negatively impact people, organizations and/or society
Similarities of domestic and international hrm : Domestic and International HRM - What are the main similarities of domestic and international HRM?
Analyze the company''s financial performance : Analyze the company's financial performance to determine the link between the company's strategic goals, strategy, and its financial performance.
Data structures assignment requiring c++ program : You should build enough new roads such that if City A was reachable from City B via some old roads, City A must be reachable from City B via some new roads.
Elucidate what it means that the preference relation : Elucidate what it means that the preference relation has a utility function representation,
360 degree feedback and human resource management : 360 Degree Feedback and Human Resource Management - discuss the relation betwwen 360 Degree Feedback and Human Resource Management?
Analyze entrepreneurship from a business : Analyze entrepreneurship from a business start-up perspective.
Communication to group of newly hired employees : You need to prepare your first presentation on appropriate communication to a group of 20 newly hired employees for their orientation. The profile of the group is as follows.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Create a solution algorithm using pseudocode

Algorithm that will receive two integer items from a terminal operator, and display to the screen their sum, difference, product and quotient.

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Implementation of graph

Give the two input nodes after the graph has been built from the command prompt.

  Data structures and algorithms

Provides learners with an understanding of how data structures are used in algorithms and enables them to design and implement data structures

  Compare the average behavior of insertion sort

Compare the average behavior of insertion sort for n elements with that of the n insertions into an initially-empty straight array implementation of a priority queue

  Determine the branching factor

Expalin the search algorithm that results from each of the following special cases. How does it relate to other algorithms we have discussed.

  Different applications of data structure

What are the different applications of Data Structure

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Data structures and algorithm design

Data Structures and Algorithm Design

  What do you meant by an rfp

Select a specific category of vertical applications to investigate. Use the Internet and any other sources of information you might have to study some of the different products that are available in that category.

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

  Find the minimum cost path from a designated node

Find the Minimum Cost Path from a designated start node to a designated destination node in a graph.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd