New Friends

AtCoder
IDabc350_d
Time2000ms
Memory256MB
Difficulty
There is an SNS used by $N$ users, labeled with numbers from $1$ to $N$. In this SNS, two users can become **friends** with each other. Friendship is bidirectional; if user X is a friend of user Y, user Y is always a friend of user X. Currently, there are $M$ pairs of friendships on the SNS, with the $i$\-th pair consisting of users $A_i$ and $B_i$. Determine the maximum number of times the following operation can be performed: * Operation: Choose three users X, Y, and Z such that X and Y are friends, Y and Z are friends, but X and Z are not. Make X and Z friends. ## Constraints * $2 \leq N \leq 2 \times 10^5$ * $0 \leq M \leq 2 \times 10^5$ * $1 \leq A_i < B_i \leq N$ * The pairs $(A_i, B_i)$ are distinct. * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $M$ $A_1$ $B_1$ $\vdots$ $A_M$ $B_M$ [samples]
Samples
Input #1
4 3
1 2
2 3
1 4
Output #1
3

Three new friendships with a friend's friend can occur as follows:

*   User $1$ becomes friends with user $3$, who is a friend of their friend (user $2$)
*   User $3$ becomes friends with user $4$, who is a friend of their friend (user $1$)
*   User $2$ becomes friends with user $4$, who is a friend of their friend (user $1$)

There will not be four or more new friendships.
Input #2
3 0
Output #2
0

If there are no initial friendships, no new friendships can occur.
Input #3
10 8
1 2
2 3
3 4
4 5
6 7
7 8
8 9
9 10
Output #3
12
API Response (JSON)
{
  "problem": {
    "name": "New Friends",
    "description": {
      "content": "There is an SNS used by $N$ users, labeled with numbers from $1$ to $N$. In this SNS, two users can become **friends** with each other.   Friendship is bidirectional; if user X is a friend of user Y, ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc350_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is an SNS used by $N$ users, labeled with numbers from $1$ to $N$.\nIn this SNS, two users can become **friends** with each other.  \nFriendship is bidirectional; if user X is a friend of user Y, ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments