HDU 6090 17多校5 Rikka with Graph(思维简单题)
For an undirected graph G with n nodes and m edges, we can define the distance between (i,j) (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 dist(i,j) equal to n.
Then, we can define the weight of the graph G (wG) as ∑ni=1∑nj=1dist(i,j).
Now, Yuta has n nodes, and he wants to choose no more than m pairs of nodes (i,j)(i≠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 wG.
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 each testcase, the first line contains two numbers n,m(1≤n≤106,1≤m≤1012).
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<vector>
using namespace std; long long calc(long long n,long long m)
{
return *(n-)*(n-)-(m-n+)*;
} int main()
{
long long T,n,m,ans;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&n,&m);
if(m>=n*(n-)/)
ans=n*(n-);
else if(m<n-)
ans=calc(+m,m)+(n--m)*(m+)**n/*和连通的内部点连*/+(n--m)*(n--m)*n/*孤立的点之间*/;
else
ans=calc(n,m);
printf("%lld\n",ans);
}
return ;
}
HDU 6090 17多校5 Rikka with Graph(思维简单题)的更多相关文章
- HDU 6106 17多校6 Classes(容斥简单题)
Problem Description The school set up three elective courses, assuming that these courses are A, B, ...
- HDU 6092 17多校5 Rikka with Subset(dp+思维)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- HDU 6095 17多校5 Rikka with Competition(思维简单题)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- HDU 6140 17多校8 Hybrid Crystals(思维题)
题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...
- HDU 6034 17多校1 Balala Power!(思维 排序)
Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...
- HDU 6077 17多校4 Time To Get Up 水题
Problem Description Little Q's clock is alarming! It's time to get up now! However, after reading th ...
- hdu 5422 Rikka with Graph(简单题)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- HDU 6143 17多校8 Killer Names(组合数学)
题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...
- HDU 6045 17多校2 Is Derek lying?
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others) Memory ...
随机推荐
- css中伪类与伪元素的区别
一:伪类:1:定义:css伪类用于向某些选择器添加特殊效果. 伪类其实与普通的css类相类似,可以为已有的元素添加样式,但是他只有处于dom无法描述的状态下才能为文档树中的元素添加样式,所以将其称为伪 ...
- apache配置一个域名读取多个路径代码(包括主干和分支)
<VirtualHost *:80> ServerAdmin 651629095@qq.com DocumentRoot "C:/wamp/www/sms/trunk/publi ...
- new 和 delete
new 和 delete 众所周知,C中的malloc和free是用来申请和释放内存的,相应的C++中也有对应的申请和释放内存的操作,即是new和delete,但是C++的new和delete比C中的 ...
- [LeetCode] 110. Balanced Binary Tree ☆(二叉树是否平衡)
Balanced Binary Tree [数据结构和算法]全面剖析树的各类遍历方法 描述 解析 递归分别判断每个节点的左右子树 该题是Easy的原因是该题可以很容易的想到时间复杂度为O(n^2)的方 ...
- 微信小程序: rpx与px,rem相互转换
官方上规定屏幕宽度为20rem,规定屏幕宽为750rpx,则1rem=750/20rpx. 微信官方建议视觉稿以iPhone 6为标准:在 iPhone6 上,屏幕宽度为375px,共有750个物理像 ...
- wps去除首字母自动大写
首字母大写功能在不是进行英文编写时是个“自作聪明”的功能,我们可能会想把它关掉.
- js中字符串转数字的方法
1.当字符串中是纯数字 例如:var s = '234'; /********** 字符串在运算操作中会被当做数字类型来处理 ***************/ s *= 1; /******* str ...
- Saiku的基本使用介绍(三)
Saiku的基本使用介绍(这里都是使用Admin用户登录系统) 1.启动安装好的Saiku ( ./start-saiku.sh ) ,浏览器使用访问系统 http://localhost:8080 ...
- 当你有双网络(内部网+互联网)时,如何透明NAT给其他电脑上网。虚拟机+爱快
一:简介 具体环境是这样的:单位没有提供互联网连接,都是内部网,linux服务器,无法连接源更新,docker无法pull镜像,python无法在线pip安装包. 真是郁闷到想死啊. 好在我的笔记本有 ...
- git-github-TortoiseGit综合使用教程(二)快速入门
:建立版本库 在github网站上创建一个版本库,并复制clone地址. git@github.com:jackadam1981/Flask_Base.git https://github.com/j ...