Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me answer this simple coding question for an online judge platform. You can write the code in either Python3 or Java8 ; whichever

Please help me answer this simple coding question for an online judge platform. You can write the code in either Python3 or Java8 ; whichever one is easier and faster. Please also provide screenshots of your output after entering the inputs; it should match the sample inputs and outputs in the question. Thank You!

I had posted this before, but got a completely wrong answer. Please provide the correct code that gives the correct output.

image text in transcribed

image text in transcribed

After the major earthquake and fires to your town, planners are assessing the damages to the roads in the city. Some roads are just gone, and others are impassable. The result is that it is impossible to get from some places to others. The planners want to get the city running quickly. Therefore they want to add as few roads as possible to get a city where everyone can reach everyone else. We'l make the simplifying assumptions that building any road is the same cost as building any other road, and that all roads are bidirectional The planners have asked you to find the minimum number of roads that they can add to the current grid so that everyone can get everywhere Input Input starts with a line containing an integer l n100 indicating the number of cities that follow. Each city's description starts with a line describing the number of road endpoints l m1000. Each endpoint is in the range 0 to m - 1. This is followed by a number 0 3r ^ min(m(m - 1)/2,10m), then a list of r pairs of endpoints which are directly connected by a usable road. Each pair appears on its own line, all pairs are distinct, and all roads connect to different endpoints

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Define training and development.

Answered: 1 week ago