QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 512 MB Total points: 100

#1401. Making Friends is Fun

Statistics

You are an agent working behind the scenes of history, working daily toward world peace. In this world, there are $N$ countries, each assigned a unique number from $1$ to $N$. Your goal is to foster the friendliest possible relationships among these $N$ countries. To plan your work as an agent, you have drawn a diagram representing the current international relations.

You prepared a large sheet of drawing paper and first placed $N$ points, each representing a country. Next, to represent the current international relations, you drew $M$ arrows connecting two countries. An arrow from the point representing country $a$ to the point representing another country $b$ indicates that "currently, country $a$ is sending an ambassador to country $b$." Hereinafter, an arrow from the point representing country $a$ to the point representing country $b$ is called an arrow $(a, b)$. The $N$ points and $M$ arrows drawn in this way represent the current international relations.

As a catalyst for friendly relations between countries, consider holding a friendship treaty conference (hereinafter simply referred to as a "conference") between two countries. For two countries $p$ and $q$ to hold a conference, a country $x$ that is sending ambassadors to both countries is required as a mediator. After the conference is held, each country sends an ambassador to the other. That is, for country $p$ and country $q$ to hold a conference, there must exist a country $x$ such that arrows $(x, p)$ and $(x, q)$ exist, and after the conference is held, you newly draw arrows $(p, q)$ and $(q, p)$. However, if an arrow is already drawn, you do not draw it again.

Your job is to choose two countries that can hold a conference and a country to mediate the conference, and then hold the conference. In simulating this work using the diagram, you decided to measure how close the world is to peace based on the number of arrows on the drawing paper. In other words, you want to know the maximum number of arrows that can be on the drawing paper by repeating the process of choosing two countries and holding a conference.

Task

Given the number of countries in this world and information about the current international relations, write a program to determine the maximum number of arrows that can be on the drawing paper by repeating the process of choosing two countries and holding a conference.

Input

Read the following input from standard input:

  • The first line contains two integers $N$ and $M$ separated by a space. $N$ represents the number of points on the drawing paper (the number of countries in this world), and $M$ represents the number of arrows on the drawing paper.
  • The following $M$ lines each contain information about an arrow on the drawing paper. The $i$-th line ($1 \le i \le M$) contains two integers $A_i$ and $B_i$ separated by a space. This indicates that an arrow is drawn from the point representing country $A_i$ to the point representing country $B_i$, meaning country $A_i$ is sending an ambassador to country $B_i$.

Output

Output the maximum number of arrows that can be realized to standard output in a single line. Note that the number of arrows should include not only those newly added by conferences but also those already drawn.

Constraints

All input data satisfies the following conditions:

  • $1 \le N \le 100\,000$.
  • $0 \le M \le 200\,000$.
  • $1 \le A_i \le N$ ($1 \le i \le M$).
  • $1 \le B_i \le N$ ($1 \le i \le M$).
  • $A_i \neq B_i$ ($1 \le i \le M$).
  • $(A_i, B_i) \neq (A_j, B_j)$ ($1 \le i < j \le M$).

Subtasks

Subtask 1 [5 points]

  • $N \le 100$ is satisfied.

Subtask 2 [30 points]

  • $N \le 5\,000$ is satisfied.

Subtask 3 [65 points]

  • There are no additional constraints.

Examples

Input 1

5 4
1 2
1 3
4 3
4 5

Output 1

10

Note

For example, you can realize 10 arrows with the following procedure:

  1. Country 2 and country 3 hold a conference with country 1 as the mediator.
  2. Country 3 and country 5 hold a conference with country 4 as the mediator.
  3. Country 2 and country 5 hold a conference with country 3 as the mediator.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.