F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Bipartite Graph

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1989    Accepted Submission(s): 704


Problem Description
Soda has a bipartite graph with $n$ vertices and $m$ undirected edges. Now he wants to make the graph become a complete bipartite graph with most edges by adding some extra edges. Soda needs you to tell him the maximum number of edges he can add.

Note: There must be at most one edge between any pair of vertices both in the new graph and old graph.
 

Input
There are multiple test cases. The first line of input contains an integer $T$ $(1 \le T \le 100)$, indicating the number of test cases. For each test case:

The first line contains two integers $n$ and $m$, $(2 \le n \le 10000, 0 \le m \le 100000)$.

Each of the next $m$ lines contains two integer $u, v$ $(1 \le u, v \le n, v \ne u)$ which means there's an undirected edge between vertex $u$ and vertex $v$.

There's at most one edge between any pair of vertices. Most test cases are small.
 

Output
For each test case, output the maximum number of edges Soda can add.
 

Sample Input
2 4 2 1 2 2 3 4 4 1 2 1 4 2 3 3 4
 

Sample Output
2 0
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 12:38:44, Gzip enabled