QOJ.ac

QOJ

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

#5337. Making Friends

统计

Note: the time limit for this problem is 3s, 50% larger than the default. The memory limit is twice the default.

There are initially $M$ ($1\le M\le 2\cdot 10^5$) pairs of friends among FJ's $N$ ($2\le N\le 2\cdot 10^5$) cows labeled $1\dots N$. The cows are leaving the farm for vacation one by one. On day $i$, the $i$-th cow leaves the farm, and all pairs of the $i$-th cow's friends still present on the farm become friends. How many new friendships are formed in total?

Input Format

The first line contains $N$ and $M$.

The next $M$ lines contain two integers $u_i$ and $v_i$ denoting that cows $u_i$ and $v_i$ are friends ($1\le u_i,v_i\le N$, $u_i\neq v_i$). No unordered pair of cows appears more than once.

Output Format

One line containing the total number of new friendships formed. Do not include pairs of cows that were already friends at the beginning.

Sample Input

7 6
1 3
1 4
7 1
2 3
2 4
3 5

Sample Output

5

On day $1$, three new friendships are formed: $(3,4)$, $(3,7)$, and $(4,7)$.

On day $3$, two new friendships are formed: $(4,5)$ and $(5,7)$.

Scoring

  • Test cases 2-3 satisfy $N\le 500$.
  • Test cases 4-7 satisfy $N\le 10^4$.
  • Test cases 8-17 satisfy no additional constraints.

Problem credits: Benjamin Qi

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.