ADS

412.: Sislovesme

A is an unordered pair i , j ( i ≠ j ) such that

When the loop later reaches i = b , the first condition fails ( b < a is false), so the pair is counted again. ∎ Lemma 3 If a pair i, j is not a mutual‑love pair, the algorithm never increments mutualPairs for it. 412. Sislovesme

Memory – The array love[1…N] is stored: . A is an unordered pair i , j

(A classic “mutual‑love” counting problem – often seen on SPOJ, LightOJ, and other online judges) 1️⃣ Problem statement You are given a group of N people, numbered from 1 to N . Each person loves exactly one other person (possibly himself). The love‑relationships are described by an array A is an unordered pair i