1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Aleks04 [339]
3 years ago
8

Using the Breadth-First Search Algorithm, determine the minimum number of edges that it would require to reach

Mathematics
1 answer:
jekas [21]3 years ago
8 0

Answer:

The algorithm is given below.

#include <iostream>

#include <vector>

#include <utility>

#include <algorithm>

using namespace std;

const int MAX = 1e4 + 5;

int id[MAX], nodes, edges;

pair <long long, pair<int, int> > p[MAX];

void initialize()

{

   for(int i = 0;i < MAX;++i)

       id[i] = i;

}

int root(int x)

{

   while(id[x] != x)

   {

       id[x] = id[id[x]];

       x = id[x];

   }

   return x;

}

void union1(int x, int y)

{

   int p = root(x);

   int q = root(y);

   id[p] = id[q];

}

long long kruskal(pair<long long, pair<int, int> > p[])

{

   int x, y;

   long long cost, minimumCost = 0;

   for(int i = 0;i < edges;++i)

   {

       // Selecting edges one by one in increasing order from the beginning

       x = p[i].second.first;

       y = p[i].second.second;

       cost = p[i].first;

       // Check if the selected edge is creating a cycle or not

       if(root(x) != root(y))

       {

           minimumCost += cost;

           union1(x, y);

       }    

   }

   return minimumCost;

}

int main()

{

   int x, y;

   long long weight, cost, minimumCost;

   initialize();

   cin >> nodes >> edges;

   for(int i = 0;i < edges;++i)

   {

       cin >> x >> y >> weight;

       p[i] = make_pair(weight, make_pair(x, y));

   }

   // Sort the edges in the ascending order

   sort(p, p + edges);

   minimumCost = kruskal(p);

   cout << minimumCost << endl;

   return 0;

}

You might be interested in
Which inequality represents all possible solutions of -12d2 -6?
qaws [65]

Answer:

f

Step-by-step explanation:

6 0
3 years ago
19. Ram and Rahim are partners in a firm sharing profits in the ratio of 3: 2. Kabir is admitted as a partner for 1/5th share of
Serhud [2]

Answer:

make me brainlist

Step-by-step explanation: firm sharing profits and losses in the ratio of 3

2. From Ist April, 2020 they decided to share the future profits equally. On this date, the General Reserve

showed a balance of 1,60,000; Revaluation of fixed assets resulted into a gain of "1,02,000 and stock resulted

to a loss of 22,000. On this date, the goodwill of the firm was valued at $3,60.000

Pas necessary journal entries for the above transactions on reconstitution of the form

Bolutions

8 0
3 years ago
In the blueprint for A rectangular balcony is 1 inch by 1.75 inches if the actual length is 7 feet what is the perimeter
Elenna [48]

Answer:

22 feet

Step-by-step explanation:

Given

  • In blue print,dimensions of rectangular balcony are, length(l)=1.75inch and breadth(b)=1inch
  • The actual length(L)=7 feet

To find the actual perimeter, we need the breadth of balcony(B)

The ratio of length to breadth in blue print must be equal to the ratio of actual length to breadth

⇒

\frac{\text{length of rectangular balcony in blueprint}}{\text{breadth of rectangular balcony in blueprint}} =\frac{\text{length of rectangular balcony actually}}{\text{breadth of rectangular balcony actually}}

\frac{l}{b} =\frac{L}{B} \\B\times l=L \times b\\B= \frac{L \times b}{l}=\frac{7 \times 1}{1.75} =4

Therefore Breadth actually=4 feet

⇒Perimeter

=2\times(length+breadth)\\=2\times(7+4)\\=2\times(11)\\=22

Therefore perimeter of rectangular balcony= 22 feet

5 0
3 years ago
Write as an algebraic expression
Mazyrski [523]

Answer:

13) x=n-11

15) x=3*10

Step-by-step explanation:

I used x as the variable. The questions are pretty straightforward. They are asking you to put the terms in the description on the right side of the equation. The questions = x. That was probably confusing, but it is correct. I hope this helped!

8 0
3 years ago
Read 2 more answers
(09.01) A biologist created the following graph to show the relationship between the temperature of water (x), in degrees Celsiu
lukranit [14]

Answer:

x-intercept:

A line that crosses the graph at x-axis.

i.e substitute y = 0 and solve for x.

As per the statement:

A biologist created the following graph to show the relationship between the temperature of water (x), in degrees Celsius, and the number of insect larvae (y) in the water

Given the graph:

y = -2x^2+20x+400

Substitute y = 0  we have;

-2x^2+20x+400 = 0

⇒-2(x^2-10x-200) = 0

⇒x^2-10x-200 =0

⇒x^2-20x+10x-200 =0

⇒x(x-20)+10(x-20)=0

⇒(x-20)(x+10)=0

By zero product property we have;

x-20 =0 and x+10 = 0

⇒x = 20 and x = -10

Therefore,  the x-intercept represents the water has no larvae at −10 degrees Celsius and 20 degrees Celsius.

6 0
3 years ago
Read 2 more answers
Other questions:
  • A wildlife conservancy maintains a ratio of 2 squirrels for every 8 birds how many birds would there be if there were 15 squirre
    14·1 answer
  • What is this the relationship between the legs and the hypotenuse of a 45 - 45 - 90 triangle?
    13·2 answers
  • Simplify the following expression:<br> 4(x+10)-3x-2-x
    11·1 answer
  • add 7. double the result. subtract 8. divide by 2. su tract the orginial selected number 1st nuber is 3 second number is 4 the t
    8·1 answer
  • The archway of the Gateway Arch shown on the Missouri quarter is 630 feet OR 7560 inches. Find out how many 4 inch stacks of qua
    13·1 answer
  • A rectangular goat pasture has dimensions represented by the expressions y – 4 and 4y^2-3y+5 .Find the area of the pasture.
    9·1 answer
  • At what point do the lines y = x + 7 and y = 5x - 13 intersect?​
    8·1 answer
  • X+5y=5 3x-5y=3 Necesito ayuda, procedimiento para resolverlos y maneras distintas de resolverlos. Denuncio a quien venga por los
    8·1 answer
  • factorise the following please due in 30min c^2+d^2. e^2/25-f^2/36. and the square root of x-4 thanks no link please​
    11·1 answer
  • Pls help …. Need it immediately ….
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!