ARC097B
D - Equals
https://gyazo.com/12b2768f38990be7bdb5dd3a2aaf087f
Thoughts.
Exchanges can be made as many times as necessary, so they can be rearranged freely within the connected components connected by the exchange.
We can use UnionFind to find the connected components and count them by checking whether pi and i are the same component for each i
Official Explanation
proof
---
This page is auto-translated from /nishio/ARC097B using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.