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
3x=12-2y write in standard form
klio [65]
Standard form is y = mx + b.

So,

3x = 12 - 2y
+ 2y     + 2y

3x + 2y = 12
-3x         - 3x

2y = -3x + 12
---     ----   ----
 2       2      2

y = (-3/2)x + 6
6 0
4 years ago
Need help with everything plz
Tom [10]

Answer:

i cant pull up the pictuer im so sorry

Step-by-step explanation:

8 0
4 years ago
How do you multiply monomials and binomials?
GrogVix [38]
To multiply mathematical expressions with only one term (monomials) and mathematical expressions with two terms (binomials), you can use the distributive property of algebra
6 0
3 years ago
Read 2 more answers
WILL GIVE BRAINLIST What is the volume of the cylinder below?
azamat

Answer:

Volume of the given oblique cylinder = 36π units³

Step-by-step explanation:

Volume of the oblique cylinder = πr²h

Here, 'r' = Radius of the circular base

'h' = Height of the cylinder

For the given oblique cylinder,

Radius of the circular base = 3 units

Height of the cylinder = 4 units

Volume of the cylinder = π(3)²(4)

                                      = 36π units³

Therefore, volume of the given oblique cylinder = 36π units³

4 0
3 years ago
V(t), left parenthesis, t, right parenthesis models the number of visitors in a park as a function of the outside temperature t
Kruka [31]

Answer:

The number of visitors increases at the same rate over both intervals

Step-by-step explanation:

The unit rate at which the number of visitors in the park increases over a given temperature interval is called the average rate of change, or ARCARCA, R, C.

To find the average rate of change of a function over an interval, we need to take the total change in the function value over the interval and divide it by the length of the interval.

Hint #22 / 3

We are asked to compare the rates at which the number of visitors increases over the interval between an outside temperature of 181818 degrees Celsius and 202020 degrees Celsius, and over the interval between an outside temperature of 202020 degrees Celsius and 272727 degrees Celsius. These correspond to the domain intervals [18,20][18,20]open bracket, 18, comma, 20, close bracket and [20,27][20,27]open bracket, 20, comma, 27, close bracket.

Let's calculate the average rate of change of VVV over those intervals:

ARC_{[18,20]}ARC

[18,20]

​

A, R, C, start subscript, open bracket, 18, comma, 20, close bracket, end subscript ARC_{[20,27]}ARC

[20,27]

​

A, R, C, start subscript, open bracket, 20, comma, 27, close bracket, end subscript

\begin{aligned} \dfrac{V(20)-V(18)}{20-18}&=\dfrac{18-10}{2}\\\\&=\dfrac{8}{2}\\\\&=4\end{aligned}\quad

20−18

V(20)−V(18)

​

​

 

=

2

18−10

​

=

2

8

​

=4

​

 \begin{aligned} \dfrac{V(27)-V(20)}{27-20}&=\dfrac{46-18}{7}\\\\&=\dfrac{28}{7}\\\\&=4\end{aligned}

27−20

V(27)−V(20)

​

​

 

=

7

46−18

​

=

7

28

​

=4

​

Hint #33 / 3

The average rate of change over the interval [18,20][18,20]open bracket, 18, comma, 20, close bracket is the same as the average rate of change over the interval [20,27][20,27]open bracket, 20, comma, 27, close bracket.

Therefore, the number of visitors increases at the same rate over both intervals.

7 0
3 years ago
Other questions:
  • F(x+4) – 2.<br> horizontal shift to<br> the right 4 and<br> horizontal shift to<br> the left 4 and
    7·1 answer
  • I need help solving this whole thing
    10·1 answer
  • Find the answer and explain.560.450-34.34872​
    10·1 answer
  • What does m mean in y=mx+b
    8·2 answers
  • The bottom of a ladder must be placed 5 feet from a wall. The ladder is 12 feet long. How far above the ground dos the ladder to
    13·1 answer
  • Uf bguvhbacndkzvhsdvnjsdbsdvbs help
    15·2 answers
  • A carpenter wants to make a ladder, but he want to calculate the required wood for it. The distance between each step is 1 foot
    5·1 answer
  • BRAINLIEST IF CORRECT<br> PLEASE HURRY
    7·2 answers
  • A map of a city uses a scale of 1cm =3.5 meters. If a road shown on the maps runs for 25cm how long is the road?
    10·2 answers
  • Patrick ate 540 apples in 9 hours. at that rate, how many apples could he eat in 4 minutes?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!