Skip to content

Instantly share code, notes, and snippets.

View Ashutosh1406's full-sized avatar
🧠
Manipal University Jaipur | Focusing

Ashutosh Ashutosh1406

🧠
Manipal University Jaipur | Focusing
View GitHub Profile
@Ashutosh1406
Ashutosh1406 / dsu.cpp class
Last active January 3, 2025 16:15
Disjoint Set Union (DSU) class
class DisjointSet {
vector<int> parent, rank, size;
DisjointSet(int n) {
size.resize(n + 1, 1);
parent.resize(n + 1);
rank.resize(n + 1, 0); //initial ranks 0
//each node is the parent of itself initially
for(int i = 0 ; i <= n; i++) {
parent[i] = i;