#P7483. [2017年杭电多校]Rikka with Graph
[2017年杭电多校]Rikka with Graph
Rikka with Graph
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
For an undirected graph with nodes and edges, we can define the distance between () as the length of the shortest path between and . The length of a path is equal to the number of the edges on it. Specially, if there are no path between and , we make equal to .
Then, we can define the weight of the graph () as .
Now, Yuta has nodes, and he wants to choose no more than pairs of nodes and then link edges between each pair. In this way, he can get an undirected graph with nodes and no more than edges.
Yuta wants to know the minimal value of .
It is too difficult for Rikka. Can you help her?
In the sample, Yuta can choose .
Input
The first line contains a number , the number of the testcases. For each testcase, the first line contains two numbers .
Output
For each testcase, print a single line with a single number -- the answer.
Sample Input
1
4 5
Sample Output
14
Source
2017 Multi-University Training Contest - Team 5