| CPUlm Winter Contest 2022 |
|---|
| Finished |
Inspired by some ideas from the Muggle world, a bunch of Ravenclaw students recently founded Studentbook. This is actually a book (magically enhanced, of course), which has a page for each Hogwarts student showing their recent social activities.
Every interested student can buy their own small version of this book, which shows recent activities of their friends. Unfortunately, this is not very popular at the moment, because everybody already knows what their friends are up to anyways.
One of the Ravenclaw students behind Studentbook, Michael Corner, has a plan to fix this. He wants to perform the powerful spell Amicitia, also known as the friendship spell. This spell acts permanently and does the following: If student $$$a$$$ and student $$$b$$$ are friends and student $$$b$$$ and student $$$c$$$ are friends as well, then student $$$a$$$ and $$$c$$$ will be made friends by the spell.
Michael was immediately alerted to the potentially catastrophic consequences of his plan. Due to the spell, it might happen, that more and more friendships will be formed, completely disrupting the social balance in Hogwarts.
But he does not want to abandon his idea so easily. Instead, he first wants to find out how many friendships would be formed by the spell.
The input consists of:
Output the number of new friendships due to the Amicitia spell.
3 3 1 2 2 3 1 3
0
4 3 1 2 3 2 3 4
3
5 3 1 2 2 3 4 5
1
| Name |
|---|


