Example: indirect friends

Here's an example from leetcode [5]. You have a bunch of friend requests, $(i,j),$ and also a bunch of forbidden “indirect friendships” $(j,k),$ which means $j$ and $k$ are not allowed to be connected through any path through the friendship network. The problem is to process the requests in order and say which ones were allowed and which were denied.

Anyway, the solution is to use union-find to represent sets of connected people.