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
Gail has $7,500 that she wants to put in a new savings account. She is
ElenaW [278]

Easy answer, Neighborhood Bank. But to see how:

$7,500 * 0.015 (1.5%) = $112.50

$112.50 a day times 360 days = $40,500

$40,500 times 20 = $810,000.

$810k times 20 = $16,200,000. (16.2mil)

$112.50 times 20 = $2,250.

So..

6 0
2 years ago
Write in standard form One and three hundred twenty-four thousandths
vlada-n [284]

Answer:

1.324

Step-by-step explanation:

7 0
4 years ago
Read 2 more answers
Rite 18.725 as a mixed number in simplest form.
Mila [183]

18.725 = 18725/1000 = 3745/200 = 749/40 = 18 29/40

so, your answer is 18 29/40

5 0
3 years ago
Help? -Factoring polynomials
OLEGan [10]

Answer:

False

Step-by-step explanation:

If we have a factor then the remainder after the division will be zero.

8 0
3 years ago
Read 2 more answers
2. A bicycling club has 58 members, of which 4 are males and the rest are females. What is the ratio of females to males?
IRISSAK [1]

Answer: 54:4

Step-by-step explanation:

6 0
3 years ago
Other questions:
  • In the diagram, ΔGHJ ≅ ΔSTU.
    14·2 answers
  • Juan and Nina are in the Junior High Orchestra. As part of the orchestra they each have to learn two instruments. Juan is learni
    14·1 answer
  • Three things in the kitchen that you can measure the height of with inches
    9·1 answer
  • Is the graph of a function rule that relates a squares area to its side length continuous or discrete? Explain
    14·1 answer
  • Find the product of 3 1/8 and 1 2/7 Express your answer in simplest form.
    8·1 answer
  • Triangle ABC, with angles and lengths as marked, is shown below.
    6·1 answer
  • I got a tricky one
    6·1 answer
  • Add the polynomias:<br>(8x^2-5x+7)+(7x^3-3x)​
    9·2 answers
  • The sum of the three numbers in 2003,two of the numbers are 814 and 519 what is the third number​
    6·2 answers
  • PLEASE HELP, MUST SUBMKT TEST ASAP!!!!!
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!