| XIII UnB Contest Mirror |
|---|
| Finished |
Falatro is a card game that has recently become very popular.
It is played with a nearly standard deck of cards, and the objective is to form a sequence of cards with the highest possible score, following some rules similar to poker. The difference in Falatro is that, in addition to the cards you have, you can buy jokers that can be used as modifiers to increase the score of your hand, depending on your hand.
Curious about the development of the game, John decided to include his own joker in the list of cards, the fidojoker. The rules for this joker are as follows: "All the cards in your hand will have paired trust relationships between them, and the score of your hand will be calculated as the sum, for each card, of the size of the smallest trust cycle that contains that card multiplied by its index." A trust relationship is formed by a pair of cards (A, B), where A trusts B and B trusts A. If a card does not participate in any trust cycle, it is considered to have size $$$1$$$.
Since John has difficulty thinking before playing, and he is not very good at math, he asked for your help to determine the score of his hand using the fidojoker.
The input consists of a single test case. The first line of the input contains two integers $$$N$$$ $$$(3 \leq N \leq 100)$$$ and $$$M$$$ $$$(2 \leq M \leq \frac{N \cdot (N-1)}{2})$$$, representing the number of cards in John's hand and the number of trust relationships between the cards, respectively. The next $$$M$$$ lines contain two integers $$$A$$$ and $$$B$$$ $$$(1 \leq A, B \leq N,\ A \neq B)$$$, indicating that cards $$$A$$$ and $$$B$$$ have a trust relationship between them. It is guaranteed that there are no multiple relationships between the same pair of cards.
The output should contain a single integer, representing the total score of John's hand.
4 41 22 31 34 1
22
6 62 44 64 16 35 13 1
63
In the first test case, the smallest cycle formed by the cards consists of $$$1$$$, $$$2$$$, and $$$3$$$. Additionally, card $$$4$$$ is not in any cycle. Thus, John's score is $$$1 \cdot 3 + 2 \cdot 3 + 3 \cdot 3 + 4 \cdot 1 = 22$$$.
| Name |
|---|


