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
Can someone help Solve these 2 questions for me? It's about Slope Intercept Forms.
Hitman42 [59]

Answer:

9.) The slope is 3 and the y-intercept is -5

10.) y = 0.25x -11

Hope this helped!

Stay safe! <3

3 0
2 years ago
An appliance is for sale at either (a) P15,999 cash or (b) on terms, P1,499 each month for the next 12 months.  Money is 9% comp
frutty [35]

Answer:

Cash price

Step-by-step explanation:

The computation is shown below:

The Interest rate per month (r) = (9% ÷ 12) = 0.75%

Now Present value of the monthly payment is

= PMT × {[(1 + rate of interest)^number of years - 1] ÷ rate of interest}

= 1,499 × {[(1 + 0.75%)^12 - 1] ÷ 0.75%}

= 18,748.89

And the cash price is 15,999

So, the cash price would be lower

5 0
3 years ago
Alonzo describes a histogram as having a cluster from 20–50, a frequency of 0 from 10–20, and a peak at 40–50. Which histogram i
Ilia_Sergeevich [38]

Answer:

A

Step-by-step explanation:

In the histogram described by the first option, the peak (18) is located at 40-50. Also, a frequency of zero is observed for range 10-20. The cluster from 20–50 means that most of the data is between this range, in fact, only 1 point is located at range 0 - 10, outside this cluster.

8 0
3 years ago
Read 2 more answers
A total of 408 tickets were sold for the school play. They were either adult tickets or student tickets. The number of student t
Marizza181 [45]
Let 2x=student tickets
Let x=adult tickets
2x+x=408
3x=408
x=136
2x=272

Number of student tickets sold:272
Number of adult tickets sold:136
5 0
3 years ago
What is the definition of an irrational number????
77julia77 [94]

Answer:

the irrational numbers are all the real numbers which are not rational numbers.

Step-by-step explanation:

7 0
3 years ago
Other questions:
  • Solve for u. -14 = u ÷ 8
    11·1 answer
  • Find the number that makes the ratio equivalent to 1:8.<br> 5:
    15·2 answers
  • Angelica's biweekly salary is $2240.<br> What is her gross monthly salary?
    5·1 answer
  • What is a central tendency
    6·1 answer
  • The distance that Sarah travels varies directly to how long she drives. She travels 440 miles in 8 hours. 
    11·2 answers
  • 25 pts to who ever can help with this question:
    9·1 answer
  • Solve the following system of equations <br> 5x+2y=1<br> y=1-3x
    9·1 answer
  • Can someone help me with this question please.
    10·1 answer
  • Which of the following contains examples of ALLITERATION? Question 2 options: “We real cool. We left school.” “We lurk late. We
    7·1 answer
  • Mike wants to be elected president of the 7th-grade student council. he wants to determine his chance of winning the election. w
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!