Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming: Right now Im trying to find a proper way to store the input of the Scanner.in file this problem deals with minimum spanning

Java Programming:

Right now Im trying to find a proper way to store the input of the Scanner.in file this problem deals with minimum spanning trees. The input file looks like this:

// Example Input

3

2 1

1 2 5

3 1

1 2 2

4 4

1 2 2

2 3 3

3 4 1

1 4 4

Okay, so the first line with 1 number indicates the number of cases (in this case its 3 cases). The lines with 2 numbers on it indicate the number of vertices and the number of edges. The lines with 3 numbers indicates the starting node #, the ending node # and the weight of the edge between the two nodes. I'm using Scanner input = new Scanner (System.in); to read the input.in file that matches as shown above. How would I write a java program that prints the sum total weight of the edges in the MST for each case (in this example 1 thru 3.... case 2 can't be solved so just print "No Solution")? I know that the second case isn't solvable too, also print if it can't be solved. I need it to work with the example input that I'm showing above.

My output I needs to look like this (printing out the sum of the edges):

Case 1 : 5

Case 2 : No solution

Case 3: 6

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

Step: 3

blur-text-image

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

Students also viewed these Databases questions

Question

7. What decisions would you make as the city manager?

Answered: 1 week ago

Question

8. How would you explain your decisions to the city council?

Answered: 1 week ago