the people 1maginary WOrld snotpna There are N cities in world numbered from 1 to N. Due to a storm, every road in world was destroyed and now no libraries are left. There are 2 types of operations : You can construct a library by giving away A dollars in ith city. You can repair an already existing road by giving away B dollars. Your goal is to make libraries such that people of every city have access to some library. People of the ith city can visit the library only if : A library exists in that city. OR There is a path from that city to a city which contains a library. ( the path should consist of repaired roads only ) You have to minimize the total cost such that people in every city can go to a library and output this minimum cost. NOTE : You can only repair the roads which existed and not build on your own. Innut Eormat

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Question of graph data structure. Skip if you can not answer. Do not reject please. Answer in c++ and answer correct only else I will downvote.
the people living in our imaginary worla
There are N cities in world numbered from 1 to N.
very
tudious.
Due to a storm, every road in world was destroyed and now no libraries are left.
There are 2 types of operations :
You can construct a library by giving away A dollars in ith city.
You can repair an already existing road by giving away B dollars.
Your goal is to make libraries such that people of every city have access to some library.
People of the ith city can visit the library only if :
A library exists in that city.
OR
There is a path from that city to a city which contains a library. ( the path should consist of repaired roads only )
You have to minimize the total cost such that people in every city can go to a library and output this minimum cost.
NOTE : You can only repair the roads which existed and not build on your own.
Input Format
The first line consists of number of test cases T. Each test case consists of 4 integers N,M,A, B. which denote number of cities,
number of roads which existed , cost to build a library , cost to repair a road.
Next M lines contains M pairs denoted by U V which indicates a road existed between U and V.
Constraints
1 <= T <= 10.
1 <= N <= 100000.
O <= M <= 100000.
1 <= A,B <= 1000000000.
1 <= U,V < = N.
Each road connects 2 distinct cities.
Output Format
Total minimum cost in dollars.
Transcribed Image Text:the people living in our imaginary worla There are N cities in world numbered from 1 to N. very tudious. Due to a storm, every road in world was destroyed and now no libraries are left. There are 2 types of operations : You can construct a library by giving away A dollars in ith city. You can repair an already existing road by giving away B dollars. Your goal is to make libraries such that people of every city have access to some library. People of the ith city can visit the library only if : A library exists in that city. OR There is a path from that city to a city which contains a library. ( the path should consist of repaired roads only ) You have to minimize the total cost such that people in every city can go to a library and output this minimum cost. NOTE : You can only repair the roads which existed and not build on your own. Input Format The first line consists of number of test cases T. Each test case consists of 4 integers N,M,A, B. which denote number of cities, number of roads which existed , cost to build a library , cost to repair a road. Next M lines contains M pairs denoted by U V which indicates a road existed between U and V. Constraints 1 <= T <= 10. 1 <= N <= 100000. O <= M <= 100000. 1 <= A,B <= 1000000000. 1 <= U,V < = N. Each road connects 2 distinct cities. Output Format Total minimum cost in dollars.
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY