A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d9/d1c/kruskal_8cpp_source.html below:

TheAlgorithms/C++: graph/kruskal.cpp Source File

10

std::array<ll, mx> parent;

12

std::vector<std::pair<ll, std::pair<ll, ll>>> edges;

14 for

(

int

i = 0; i <

node

+ edge; ++i) {

20 while

(parent[i] != i) {

21

parent[i] = parent[parent[i]];

27void

join(

int

x,

int

y) {

30

parent[root_x] = root_y;

35 for

(

int

i = 0; i < edge; ++i) {

36 ll

x = edges[i].second.first;

37 ll

y = edges[i].second.second;

38 if

(root(x) != root(y)) {

39

mincost += edges[i].first;

48 int

from = 0, to = 0, cost = 0, totalcost = 0;

49

std::cin >>

node

>> edge;

50 if

(

node

== 0 && edge == 0) {

54 for

(

int

i = 0; i < edge; ++i) {

55

std::cin >> from >> to >> cost;

56

edges.emplace_back(make_pair(cost, std::make_pair(from, to)));

59

sort(edges.begin(), edges.end());

60

std::cout << kruskal() << std::endl;

int main()

Main function.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4