From cf7289fee32fea6bec245543052f29158a60d9a3 Mon Sep 17 00:00:00 2001 From: Aayush Vyas <70998175+AayushVyasKIIT@users.noreply.github.com> Date: Sat, 4 Sep 2021 08:46:40 +0530 Subject: [PATCH] Update dsu_union_rank.cpp --- data_structures/dsu_union_rank.cpp | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/data_structures/dsu_union_rank.cpp b/data_structures/dsu_union_rank.cpp index da2a842c2..6e9f39cb6 100644 --- a/data_structures/dsu_union_rank.cpp +++ b/data_structures/dsu_union_rank.cpp @@ -42,7 +42,7 @@ class dsu{ */ explicit dsu(uint64_t n){ p.assign(n,0); - //initially all of them their own parents + ///initially all of them are their own parents depth.assign(n,0); setSize.assign(n,0); for(uint64_t i=0;idepth[y]){ std::swap(x,y); } - //making the shallower tree' root parent of the deeper root + ///making the shallower tree, root parent of the deeper root p[x] = y; - //if same depth then increase one's depth + ///if same depth, then increase one's depth if(depth[x] == depth[y]){ depth[y]++; } - //total size of the resultant set + ///total size of the resultant set setSize[y]+=setSize[x]; } /** @@ -124,14 +124,14 @@ class dsu{ }; /** - * @brief Self-implementation Test case #1 + * @brief Self-implementations, 1st test * @returns void */ static void test1() { /* checks the parents in the resultant structures */ uint64_t n = 10; /// ans = {7,5}; for(uint64_t i=0;i ans = {2,1,10}; for(uint64_t i=0;i