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
A number plus one equals negative seventeen.
alexdok [17]
-18 + 1 = -17

I hope this was the answer you were looking for!:)
4 0
3 years ago
Read 2 more answers
For questions 15-17 use this triangle.
SIZIF [17.4K]

Answer:

Part A)  The length of the hypotenuse of triangle ABC is

 

Part B) The length of the shorter leg of triangle ABC is

Part C) The length of the longer leg of triangle ABC is

Step-by-step explanation:

see the attached figure  to better understand the problem

Step 1

Find the length of the longer leg of triangle ABC  (side BC)

we know that  

In the right triangle DBC  

substitute the values and solve for BC

Step 2

Find the length of the shorter leg of triangle ABC  (side AC)

we know that  

In the right triangle ACD

substitute the values and solve for AC

Step 3

Find the length of the hypotenuse of triangle ABC (side AB)

Applying the Pythagoras theorem

we have

substitutes

 

8 0
2 years ago
Tony has $727.29 in his checking account. He must maintain a $500 balance to avoid a fee. He wrote a check for $248.50 today. Wr
JulsSmile [24]

Answer:

727.29 − 248.50 + x ≥ 500; x ≥ $21.21

Step-by-step explanation:

<em>Write down all the data given :</em>

Beginning amount : $727.29

Balance to be maintained : $ 500

Check : $248.5

Current balance = 727.29 - 248.5 = $478.79

<em>Tony must maintain a balance of $500 so he should have at least $21.21 more (500-478.79)</em>

727.29 - 248.5 + 21.21 = 500

500=500

<em>x can be 21.21 or greater than that which would maintain the balance of $500 or more.</em>

<em>Therefore the third statement is correct.</em>

727.29 − 248.50 + x ≥ 500; x ≥ $21.21

!!

7 0
4 years ago
The FIFO method of computing equivalent units excludes the beginning inventory costs in computing the cost per equivalent unit f
Svetach [21]

Answer:

Yes

Step-by-step explanation:

The FIFO  method of process costing assumes that the opening work in process is the first group of units to be processed and completed during the current period. <u><em>The opening work in progress is charged separately to completed production and the cost per unit is based only on the current period costs and the production for the current period</em></u>. The closing work in process is assumed to come from the new units started during the period.

3 0
3 years ago
What is the approximate radius of a sphere of volume 528 m³? round the answer to hundreth
makvit [3.9K]

\\ \sf\longmapsto V=\dfrac{4}{3}πr^3

\\ \sf\longmapsto 528=\dfrac{4}{3}πr^3

\\ \sf\longmapsto \pi r^3=528\times \dfrac{3}{4}

\\ \sf\longmapsto πr^3=32(3)

\\ \sf\longmapsto \pi r^3=96

\\ \sf\longmapsto 3.14r^3=96

\\ \sf\longmapsto r^3=\dfrac{96}{3.14}

\\ \sf\longmapsto r^3=30.57

\\ \sf\longmapsto r=3.09m=3.1m

5 0
3 years ago
Read 2 more answers
Other questions:
  • What is 15% of $32.50 and please explain how you got your answer please
    6·2 answers
  • Joe runs one lap around a track in 80 seconds. Joe and Jim start at the same point and run the track in opposite directions. The
    5·1 answer
  • What is the area of a rectangle with width 25 inches and length 35 inches? 1/5 in² 6/25 in² 6/10 in² 2 in²
    14·2 answers
  • Every morning Jim runs for 30 minutes if Jim runs for 8 miles per hour how far does he travel
    12·2 answers
  • Solve using the quadratic equation.<br> –3x2 - 4x + 10 = 0
    11·1 answer
  • Factor b3 +b2 + b + 1.
    9·1 answer
  • 100 points! Help on 10 and I will mark brainliest
    13·2 answers
  • Perhaps..............
    5·1 answer
  • What will the function f(x) = x² look like translated 3<br> units right and 8 units down?
    5·1 answer
  • How can you analyze connections between linear equations and use them to solve problems
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!