kruskal c++
C++
int find(int x) {
while ( x != link[x]) x = link[x];
return x;
}
int unite(int a, int b) {
if (size[a] > size[b]) swap(a, b);
size[a] += size[b];
link[b] = a;
}
int kruskal() {
int link[N+1], size[N+1];
sort(adj.begin(), adj.end());
for (int i=0; i<N; i++) {
link[i] = i;
size[i] = 1;
}
int cnt = 0;
for (int i=0; i<adj.size(); i++) {
int a = find(adj[i].second.first);
int b = find(adj[i].second.second);
if (a != b) { unite(a, b); cnt += adj[i].first; }
}
return cnt;
}
Also in C++:
- Title
- cpp create lambda with recursion
- Category
- C++
- Title
- c++ find object in vector by attribute
- Category
- C++
- Title
- dijkstra in c++
- Category
- C++
- Title
- Find a element in a map C++
- Category
- C++
- Title
- c++ overloaded == operator
- Category
- C++
- Title
- vector concat c++
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- how to create object in c++
- Category
- C++
- Title
- Convert binary tree to a doubly linked list
- Category
- C++
- Title
- in c, is class uppercase or lowercase
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- translate
- Category
- C++
- Title
- varint index
- Category
- C++
- Title
- how to find the mode of a vector c++
- Category
- C++
- Title
- variabvles in c++
- Category
- C++
- Title
- two sum problem in c++
- Category
- C++
- Title
- cannot jump from switch statement to this case label c++
- Category
- C++
- Title
- pairs in c++
- Category
- C++
- Title
- what is time complexity of swap function
- Category
- C++
- Title
- primeros numeors primos menores que
- Category
- C++
- Title
- c++ reverse vector
- Category
- C++
- Title
- log base e synthax c++
- Category
- C++
- Title
- cout console
- Category
- C++
- Title
- how to sort a vector in c++
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- Newton's sqrt in c++
- Category
- C++
- Title
- can you use a return to print a string when referencing an integer c++
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- how to print eachh chars in string data type in c++
- Category
- C++
- Title
- sum of integer in array c++
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- double pointers C++
- Category
- C++
- Title
- best fit algorithm
- Category
- C++
- Title
- monotonic deque
- Category
- C++
- Title
- std::substring
- Category
- C++
- Title
- how to find the index of an element in a vector c++
- Category
- C++
- Title
- what is difffrence between s.length() and s.size()
- Category
- C++
- Title
- c++ convert int to cstring
- Category
- C++
- Title
- write to file in C++
- Category
- C++
- Title
- mark occurances of elements in array cpp
- Category
- C++
- Title
- file objects in c++
- Category
- C++
- Title
- mingw32/bin/ld.exe: C:\Users\mfrom\AppData\Local\Temp\ccSKcRks.o:PizzaPi.cpp:(.text$_ZN5PizzaC2Ev[__ZN5PizzaC2Ev]+0xa): undefined reference to `vtable for Pizza' collect2.exe: error: ld returned 1 exit status
- Category
- C++
- Title
- can you use rand to read in from an external file inc++
- Category
- C++
- Title
- c++ char print fixed
- Category
- C++
- Title
- how to remove maximum number of characters in c++ cin,ignore
- Category
- C++
- Title
- euler phi gfg
- Category
- C++
- Title
- insert function in c++ vector
- Category
- C++
- Title
- array 2d to 1d
- Category
- C++
- Title
- c++ vector
- Category
- C++
- Title
- pair in c++
- Category
- C++
- Title
- while loops
- Category
- C++
- Title
- mao two drivers c++
- Category
- C++
- Title
- how to make string get spaces c++
- Category
- C++
- Title
- insert at position in vector c++
- Category
- C++
- Title
- length of 2d array c++
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- run program until ctrl-d c++
- Category
- C++
- Title
- qt graphics scene map cursor position
- Category
- C++
- Title
- repeating character in c++
- Category
- C++
- Title
- calculate sum in c++
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- how to append to a vector c++
- Category
- C++
- Title
- chess perft 5
- Category
- C++
- Title
- iterate 2d array c++
- Category
- C++
- Title
- how to know the correct class of objects cpp
- Category
- C++
- Title
- preorder traversal
- Category
- C++
- Title
- 1d fixed length arrays c++
- Category
- C++
- Title
- double to float c++
- Category
- C++
- Title
- for loop in c++ hackerrank solution
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- Operator overloading in C++ Programming
- Category
- C++
- Title
- c++ main function
- Category
- C++
- Title
- what is a header in c++
- Category
- C++
- Title
- properties of a set c++
- Category
- C++
- Title
- copy a part of a vector in another in c++
- Category
- C++
- Title
- c++ class member initialization
- Category
- C++
- Title
- c++ how to loop through a vector but not the last element
- Category
- C++
- Title
- c++ public inheritance not getting protected
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- SFML window
- Category
- C++
- Title
- append string to another string c++
- Category
- C++
- Title
- c++ remove element from vector
- Category
- C++
- Title
- convert string to stream c++
- Category
- C++
- Title
- getline not working c++
- Category
- C++
- Title
- c++ how to make a negative float positive
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- __builtin_ctz
- Category
- C++
- Title
- formal parameter c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorAbort signal from abort(3) (SIGABRT)
- Category
- C++
- Title
- binary serach in c++
- Category
- C++
- Title
- for loop
- Category
- C++
- Title
- c++ allocate dynamic with initial values
- Category
- C++
- Title
- how to extract substring from string in c++
- Category
- C++
- Title
- font awesome bootstrap cdn
- Category
- C++
- Title
- decimal to hex cpp
- Category
- C++
- Title
- arrow operator c++
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- else if c++
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- hobo 8
- Category
- C++