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;
}
(Although completely unnecessary, if you could explain how to write this out into an equation that would be amazing. As much as I’d appreciate an answer, it’s also be cool to know how to do it. C:)
we are given that
8 more than a number is greater than or equal to 0
Let's assume that number as 'x'
8 more than a number is
now, it is greater than or equal to 0
so, we can write as
now, we can solve for x
Subtract both sides 8
...............Answer
there were 12 cups of cereal in the box, predict about how many raisins should there
be in the box?
Answer:
counted 27 raisins. If
there were 12
Answer: 2x^3+5
Step-by-step explanation:
$23. She has $65 that she is able to spend. Which equation can be used to
determine how many CDs Shayla could buy?
Answer:
w + 6 ≥ 27
Step-by-step explanation:
A number w is the variable w.
Increased by 6 means being added by 6.
Answer:
what?
Step-by-step explanation: