hdu 多校联赛 Rikka with Graph
来源:互联网 发布:java api中文版下载 编辑:程序博客网 时间:2024/06/05 10:43
Rikka with Graph
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
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 G with n nodes and m edges, we can define the distance between (i,j) (\text{dist}(i,j)) as the length of the shortest path between i and j. The length of a path is equal to the number of the edges on it. Specially, if there are no path between i and j, we make \text{dist}(i,j) equal to n.
Then, we can define the weight of the graph G (w_G) as \sum_{i=1}^n \sum_{j=1}^n \text{dist}(i,j).
Now, Yuta has n nodes, and he wants to choose no more than m pairs of nodes (i,j)(i \neq j) and then link edges between each pair. In this way, he can get an undirected graph G with n nodes and no more than m edges.
Yuta wants to know the minimal value of w_G.
It is too difficult for Rikka. Can you help her?
In the sample, Yuta can choose (1,2),(1,4),(2,4),(2,3),(3,4).
For an undirected graph G with n nodes and m edges, we can define the distance between (i,j) (\text{dist}(i,j)) as the length of the shortest path between i and j. The length of a path is equal to the number of the edges on it. Specially, if there are no path between i and j, we make \text{dist}(i,j) equal to n.
Then, we can define the weight of the graph G (w_G) as \sum_{i=1}^n \sum_{j=1}^n \text{dist}(i,j).
Now, Yuta has n nodes, and he wants to choose no more than m pairs of nodes (i,j)(i \neq j) and then link edges between each pair. In this way, he can get an undirected graph G with n nodes and no more than m edges.
Yuta wants to know the minimal value of w_G.
It is too difficult for Rikka. Can you help her?
In the sample, Yuta can choose (1,2),(1,4),(2,4),(2,3),(3,4).
Input
The first line contains a number t(1 \leq t \leq 10), the number of the testcases.
For each testcase, the first line contains two numbers n,m(1 \leq n \leq 10^6,1 \leq m \leq 10^{12}).
For each testcase, the first line contains two numbers n,m(1 \leq n \leq 10^6,1 \leq m \leq 10^{12}).
Output
For each testcase, print a single line with a single number -- the answer.
Sample Input
14 5
Sample Output
14
这道题做的时候掉到坑里去了 忘了环状和链状的路径都比放射状的长度长 加上后面一个变量没用long long类型 就这么傻傻的错了十几遍 最近智商下降有点严重(┬_┬)、、
ac代码:
#include<bits/stdc++.h>using namespace std;int main(){ int t; scanf("%d",&t); while(t--) { long long n,m; long long ans=0; scanf("%lld%lld",&n,&m); if(m>=n) { if(n*(n-1)/2<=m) {ans=n*(n-1); } else if(n*(n-1)/2>m) {ans=n*(n-1)+(n*(n-1)/2-m)*2; } } else if(m==n-1) { ans=(n-2)*(n-1)*2+2*(n-1); } else if(m<n-1) { ans+=(m-1)*m*2+2*m; long long g=n-(m+1); ans+=g*(m+1)*n*2; ans+=g*(g-1)*n; } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- hdu 多校联赛 Rikka with Graph
- hdu 多校联赛 Rikka with Competition
- HDU6090 Rikka with Graph(贪心,思路,2017 HDU多校联赛 第5场)
- hdu 多校联赛 6092 Rikka with Subset
- HDU 2017 多校联赛5 1011 Rikka with Competition
- Rikka with Graph HDU
- HDU6090---Rikka with Graph(2017多校联赛:思路题)
- hdu 5422 Rikka with Graph
- HDU 5422:Rikka with Graph
- hdu-5422 Rikka with Graph
- hdu 5422 Rikka with Graph
- HDU 5422 Rikka with Graph
- HDU 5631 Rikka with Graph
- HDU 5631 Rikka with Graph
- HDU 5631 Rikka with Graph
- HDU 5631 Rikka with Graph
- HDU 5631 Rikka with Graph
- HDU 6090 Rikka with Graph
- HttpClient源码解析系列:第五篇:HttpClientBuilder中的配置分析
- 从请求中获取当前用户的三种方法
- 《reinforcement learning:an introduction》第十一章《Off-policy Methods with Approximation》总结
- 重复插入
- angularjs Controller之间的通信
- hdu 多校联赛 Rikka with Graph
- delegate的使用
- 滑动窗口
- javaweb的登录验证过滤器的实现
- this、static关键字(静态变量、方法、代码块)| 单例模式
- eclipse java/jee oxygen 下载
- OpenCV学习笔记(3)——Scalar数据类型理解
- Js_Dom(2)__Dom基础<方法(重点)>
- android性能测试封装工具----ctrace4android,附性能测试的3个例子