Hello again :D
Here is my DSU struct in c++ because there isn't any in codeforces. I added some features like making a DSU equal to another or clearing DSU.
use it like :
DSU tmp(n);
Any suggestion comment below :D
UPD1 : I added more features
UPD2 : Now you can merge two DSUs. (like if you want to add every edge in graph A to graph B) https://paste.ubuntu.com/p/Xz3BNBGcN4/
clear
method doesn't resetSetCnt
variable. Also second constructor doesn't copy same variable.THX, fixed.
(p1 == p2? false: (par[p1] = p2) | 1)
WHY? It doesn't make your code faster, just write it normally in 2-3 lines.Thanks for your suggestion. I will make it better
it's better now i think:)
You can just swap them
if (sz[p1] < sz[p2])
In the case of calling set_union and both nodes have the same root, you will double the size of that component in
sz[p1] += sz[p2]
, please fix that.wow, thanks fixed.
It's rather redundant to use
const int &
in the constructor. Just useconst int
without reference. It's faster and also more logical. Also, try to avoid using variable names that start with capital letters.