Triangle Toggle

AtCoder
IDarc205_b
Time2000ms
Memory256MB
Difficulty
There is a complete graph with $N$ vertices numbered $1$ to $N$. Each edge is colored black or white. For $i=1,2,\ldots,M$, the edge connecting vertices $U_i$ and $V_i$ is colored black, and all other edges are colored white. You can perform the following operation zero or more times. * Choose a triple of integers $(a,b,c)$ satisfying $1\le a < b < c \le N$, and repaint each of the following three edges: white to black, black to white. * The edge connecting vertices $a$ and $b$ * The edge connecting vertices $b$ and $c$ * The edge connecting vertices $a$ and $c$ Find the maximum number of edges that can be colored black when you perform operations appropriately. ## Constraints * $3\le N\le 2\times 10^5$ * $\displaystyle 0\le M\le 2\times 10^5$ * $1\le U_i < V_i \le N$ * $(U_i , V_i) \neq (U_j , V_j)$ $(i \neq j)$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $M$ $U_1$ $V_1$ $U_2$ $V_2$ $\vdots$ $U_M$ $V_M$ [samples]
Samples
Input #1
4 1
1 2
Output #1
5

By performing two operations as follows, you can make the number of black edges $5$.

*   Choose $(a,b,c)=(1,3,4)$. Then, we have the following four black edges.
    *   The edge connecting vertices $1$ and $2$
    *   The edge connecting vertices $1$ and $3$
    *   The edge connecting vertices $1$ and $4$
    *   The edge connecting vertices $3$ and $4$
*   Choose $(a,b,c)=(2,3,4)$. Then, we have the following five black edges.
    *   The edge connecting vertices $1$ and $2$
    *   The edge connecting vertices $1$ and $3$
    *   The edge connecting vertices $1$ and $4$
    *   The edge connecting vertices $2$ and $3$
    *   The edge connecting vertices $2$ and $4$

You cannot make the number of black edges more than $5$, so output $5$.
Input #2
7 3
1 2
2 3
3 6
Output #2
20
Input #3
123123 0
Output #3
7579575003

Be careful about overflow.
API Response (JSON)
{
  "problem": {
    "name": "Triangle Toggle",
    "description": {
      "content": "There is a complete graph with $N$ vertices numbered $1$ to $N$. Each edge is colored black or white. For $i=1,2,\\ldots,M$, the edge connecting vertices $U_i$ and $V_i$ is colored black, and all other",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc205_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a complete graph with $N$ vertices numbered $1$ to $N$. Each edge is colored black or white. For $i=1,2,\\ldots,M$, the edge connecting vertices $U_i$ and $V_i$ is colored black, and all other...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments