Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:07:40+00:00 2026-06-13T18:07:40+00:00

I am trying the following problems from several hours , but not able to

  • 0

I am trying the following problems from several hours , but not able to get a correct logic for it.

You are in a planning team, which is in charge of laying
out an auxiliary electricity grid. The purpose of this
auxiliary grid is to power the lamp posts on junctions
of a small town in case of power outage. Your team is
given k generators. You can place these generators
anywhere in the grid and each generator can turn on
all the lamps that have a connection to it via the grid
(there exists a path). For each road in the town, you are
given the cost of laying down a cable in the grid to connect the two
junctions at the endpoints of that road. Given the layout of the town,
your task is to lay down the minimum cost grid and install
the generators on it such that you can turn on all the lampposts on
the junctions of the town.

Input:
The first line contains the number of cases t. Then, t cases follow.
The first line of each case contains three integer n, m, and k.
The junctions are numbered 1 to n. Then, m lines follow.
Each line contains three integers i, j, c. The integers i and j
are between 1 and n and denote the two junctions at the two endpoints of a road.
The third integer, c, is the cost
of laying down a cable in the grid on this road.

Output:
You should output t lines, one for each case. For each case output the
minimum cost grid. If this task is impossible (i.e. there is no way to
turn all the lamps on with k generators),
output “Impossible!” (quotes for clarity)

Constraints:
1 <= t <= 25
1 <= n <= 2000
0 <= m <= n(n-1)/2
0 <= c <= 1000000

Sample Input:
2
3 1 1
1 2 10
6 7 2
1 2 20
1 3 5
1 4 10
2 3 8
2 4 15
3 4 2
5 6 9

Sample Output:
Impossible!
24

Explanation:
In the first case, the junctions 1 and 2 are disconnected from
junction 3 and you cannot turn on all the lampposts with only
one generator. You need at least two generators.In the second case,
you can lay down cable on the roads (1 3), (2 3), (3 4), and (5 6) and then
install one generator on junction 1 and one generator on junction 5.

How to solve this problem efficiently?Rightnow I have no idea other than BruteForce.
Will modified Kruskal work here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:07:42+00:00Added an answer on June 13, 2026 at 6:07 pm

    The solution you want is a collection of disconnected spanning trees. If you took all the lines not in the solution and gave them the same very large cost then you could find a minimum spanning tree and discard the lines with very large costs to find the solution.

    This is obviously impossible, but Kruskal’s algorithm works by starting with the edge with least cost and carrying on in order of steadily increasing cost. So if you just stop it when you have k disconnected components you will get the same answer as if you had done this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get several informations from google calendar's API in JAVA. While trying
I have the following problems: First: I am trying to do a 32-spaces bitwise
Just as a learning experience, I'm trying to code the following problems in C.
I am having problems trying to do the following. I am trying to incorporate
Trying to use JSTL but have the following problem: Index.xhtml page: <?xml version=1.0 encoding=UTF-8?>
I get the following problem when trying to open an ASPX page in FireFox:
I've been learning Python for several months but now finding some problems with my
I hope someone can help me as I've already spent several hours trying to
I have the following java.util.Timer but it does not seem to execute and I
I've been trying to get the following method cleaned up using more sensible and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.