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
"Question": Expand (2x-3y)^3<br><br> Real question: Why am I not ace rank yet?
Hitman42 [59]

Answer: (6x-3y)3 or maybe not possible to do

Step-by-step explanation

multiply 3x2 and get 6. Multiply 3x3 and get 9.

5 0
2 years ago
Read 2 more answers
Can someone please helpp
NeTakaya

Answer:

B

Step-by-step explanation:

8 0
3 years ago
PLEASE ANSWER ASAP!!! Using the given equation find the missing coordinates of the points and then find the slope of the line fo
Andrei [34K]

Answer:

Step-by-step explanation:A.

B.

Slope =

Step-by-step explanation:

We are given the equation of the line as .

A. The co-ordinate is given by

Substituting the value , we get,

implies  implies   i.e. 3x = -1 i.e.

Thus, the co-ordinate is .

B. The co-ordinate is given by

Substituting the value , we get,

implies  implies   i.e. 9y = 0 i.e. y= 0

Thus, the co-ordinate is .

Since, the slope of a line is given by .

We get,

Slope = .

i.e. Slope = .

i.e. Slope = .

Hence, the slope of the line is .

5 0
2 years ago
Julian has to read 4 articles for school. He has 8 nights to read them. He decides to read the same number of articles each nigh
daser333 [38]

<u><em>Answer:</em></u>

a. He will have to read half an article per night

b. Fraction of the reading assignment read each night = \frac{0.5}{4}=\frac{1}{8}

<u><em>Explanation:</em></u>

<u>Part a:</u>

<u>We are given that:</u>

number of articles to read = 4 articles

number of nights = 8 nights

To get the number of articles that he should read per night, we will simply divide the the number of articles by the number of nights

<u>Therefore:</u>

number of articles to read per night = \frac{4}{8}=\frac{1}{2} articles per night

<u>Part b:</u>

Now, we know that he will read half an article each night from a total of 4 articles

To get the fraction of the reading assignment read each night, we will divide the number of articles read each night by the total number of assignments

<u>Therefore:</u>

Fraction of the reading assignment read each night = \frac{0.5}{4}=\frac{1}{8}

Hope this helps :)

5 0
3 years ago
What are two ways to find the slope of a line?​
DedPeter [7]

Answer:

m = (y - y)/(x - x)

Rise/run

Step-by-step explanation:

4 0
2 years ago
Other questions:
  • Percent of decrease of 120 to 52
    11·1 answer
  • 4x=124 what is the solution to this equation?
    8·2 answers
  • Find the margin of error for a poll, assuming that 95% confidence level and π = 0.5.(a) n = 50 (Round your answer to 4 decimal p
    5·1 answer
  • To convert 420 seconds to minutes, which ratio should you multiply by?<br> PICTURE INCLUDED
    12·1 answer
  • Heeelppppp plsssss pic on top
    10·1 answer
  • PLEASE ANSWER solve x^(2)+5x+6=0
    11·2 answers
  • What is the remainder when x^6-4x^4+4x^2-10 is divided by (x+3)
    6·1 answer
  • PLZZZZ HELP ME I’ll give brainliest answer
    5·1 answer
  • What do the blue lines mean also what is the answer
    14·2 answers
  • Which ordered pair is NOT in the solution set of −2x + 3y  ≥  12?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!