đź‘‘ The War of Crowns: Rise of the Ranks in the Realm of Disjointed Kings
"Peace can be forged. But power must be respected."
— Inscription above the Obsidian Throne
In the age after the unification, after the scroll of parent
was passed to every soul,
the Realms believed the worst was behind them.
But unity without order is like a sword without a hilt —
powerful, yes, but dangerous.
Many kings had joined together.
But pride — old, ancient pride — stirred once again.
“Why,” asked one warlord, “must my kingdom kneel to one weaker than mine?”
The winds answered not with words, but with fire.
And so the Archivist returned.
"If you must unite again, let the **stronger king rule."
Thus began the Age of the Rank,
and with it, the reforging of the UnionFind
scroll — now built to honor strength.
📜 The Scrolls of Strength
class UnionFind {
vector<int> parent;
vector<int> rank;
public:
UnionFind(int n) {
parent.resize(n);
rank.resize(n, 0);
for (int i = 0; i < n; ++i)
parent[i] = i;
}
This time, the Archivist did not walk alone.
He carried two scrolls:
- One to name the king (
parent[i] = i
) - And one to measure the might of each realm (
rank[i] = 0
)
Every kingdom began with equal strength.
Not in steel or numbers — but in height, for kingdoms now grew as trees.
A realm with more levels was stronger — not taller in walls, but deeper in roots.
đź§ The Quest for Kingship, Revisited
int find(int v) {
if (parent[v] == v)
return v;
return parent[v] = find(parent[v]);
}
Though kingdoms grew, the lesson of the knight Kael remained unchanged.
“Follow your ancestry. Walk the crowns. Reach the source.”
And as before, the knight carved shortcuts behind him,
so others could follow the truth faster.
The find(v)
remained untouched — a sacred ritual unchanged by time.
But now, what came after would honor not just unity, but hierarchy.
⚔️ The Judgement of Rank
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a != b) {
if (rank[a] < rank[b])
parent[a] = b;
else if (rank[a] > rank[b])
parent[b] = a;
else {
parent[b] = a;
rank[a]++;
}
}
}
In the Valley of Judgment, two kings stood once more.
But this time, there would be no blind bending of the knee.
The Archivist raised his staff and spoke:
"Show me your might."
He looked not at their crowns — but at the depth of their trees.
The one with greater rank — whose kingdom was deeper, more layered —
would remain king.
- If
rank[a] < rank[b]
, thena
was absorbed intob
- If
rank[b] < rank[a]
, thenb
was absorbed intoa
But if their might was equal…
A storm of energy struck the earth. One ruled — and grew mightier.
The tree was raised by one level:rank[a]++
.
The realm had not just unified,
it had grown stronger, built on respect.
No longer was this simply the unite()
of old.
This was ranked war, where power decided peace.
đź§Ş The Whispering Stones
bool connected(int a, int b) {
return find(a) == find(b);
}
};
Still, scouts and travelers moved across the realm,
placing stones on crossroads and asking:
“Do these lands serve the same king?”
The Archivist listened.
He cast find(a)
and find(b)
and marked the truth upon the stones.
If they answered equally, the message was carved:
"Yes — one kingdom."
If not, a symbol of unrest was drawn.
"No — division lingers."
Thus, connected(a, b)
lived on.
🌄 A New Realm, Stronger Than Before
int main() {
UnionFind realm(10);
realm.unite(0, 1);
realm.unite(2, 3);
realm.unite(4, 5);
realm.unite(1, 2);
realm.unite(5, 6);
realm.unite(3, 4);
realm.unite(0, 6);
}
Ten shards of the world.
One by one, they bound together — but now with rank guarding the crown.
- Kingdoms didn’t just join — they respected strength.
- No weak king ruled the strong — only the worthy wore the crown.
And as each union took place, the tree grew taller, but only when needed.
No unnecessary height. No careless union.
Only purposeful merging — to keep the realm shallow, swift, and sovereign.
🔥 Etched Into Mind: The Essence of Union by Rank
-
parent[]
— every warrior's belief about who leads him -
rank[]
— how powerful the king’s lineage is; the depth of his influence -
find(v)
— follow your ancestry, and record the truth on return -
unite(a, b)
— if kings differ, the mightier absorbs the other- If equal, one is chosen, and his tree grows taller by one
connected(a, b)
— check if paths lead to the same crown
Now, in any kingdom, any battlefield, any interview…
When you're asked:
"Do you know Union-Find with Rank?"
You won't write code.
You’ll remember the Archivist,
the trees of strength,
and the day kings learned to bow with dignity.
Because some truths are not memorized…
They are forged in saga.
Top comments (0)