# Thuật toán Kruskal ## Kiến thức cần biết - Disjoint Set Union - - ## Khái niệm ## Ví dụ Cho đồ thị vô hướng $G$ gồm $n$ đỉnh và $m$ cạnh nối giữa 2 đỉnh $u, v$ với trọng số là $w$. Tìm c ## Cài đặt ```cpp= #include <iostream> #include <vector> #include <algorithm> #include <numeric> using namespace std; struct DSU { vector<int> p, lvl; void init(int n) { p.resize(n+1); iota(begin(p), end(p), 0); lvl.assign(n, 0); } int find(int u) {return parent[u] == u ? u : (parent[u] = find(parent[u])); } bool unite(int u, int v) { } bool connected(int x, int y) { return find(x) == find(y); } } dsu; int main() { } ``` ## Đánh giá độ phức tạp ## Bài tập vận dụng 1. [NKCITY](https://oj.vnoi.info/problem/nkcity) Code mẫu ```cpp= ``` 2. [1927 - F](https://codeforces.com/contest/1927/problem/F) Code mẫu ```cpp= ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up