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 ...
随机推荐
- HDU-2586-裸LCA入门-tarjan离线
http://acm.hdu.edu.cn/showproblem.php?pid=2586 给出一颗树和边权,询问两点距离. 考虑tarjan离线做法,做法很巧妙,当前进行到u,对他的儿子v,当v子 ...
- python使用MySQLdb模块连接MySQL
1.安装驱动 目前有两个MySQL的驱动,我们可以选择其中一个进行安装: MySQL-python:是封装了MySQL C驱动的Python驱动:mysql-connector-python:是MyS ...
- 接口测试--postman简介
一.什么是接口测试 接口测试是测试系统组件间接口的一种测试.接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点.测试的重点是要检查数据的交换,传递和控制管理过程,以及系统间的相互逻辑 ...
- Hadoop---18/06/03 20:15:52 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable starting yarn daemons
WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin- ...
- noip2016组合数问题
题目描述 组合数 Cnm 表示的是从 n 个物品中选出 m 个物品的方案数.举个例子,从 (1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3) 这三种选择方法.根据组合数的 ...
- PhpDocumentor 生成文档
最近项目需要phpdoc生成文档,首先安装PhpDocumentor,利用pear安装: 切换用户: su root 安装PhpDocumentor: pear install PhpDocument ...
- 3G 4G 5G中的网络安全问题——文献汇总
Modeling and Analysis of RRC-Based Signalling Storms in 3G Networks 还是使用状态机模型来做恶意UE识别 https://san.ee ...
- Linux定时计划(crontab)使用说明
一.设置定时计划步骤 第一步,编缉计划文件:crontab -e 第二步,在文件中写入计划,格式如:minute hour day month week command.如0 8 * * * sh / ...
- svn分支使用 SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤
比较好的介绍了分支的创建和使用. 转:http://blog.csdn.net/vbirdbest/article/details/51122637
- nginx test
nginx 1◆ /etc/init.d/httpd start yum install httpd -y 192.168.163.104 lsof -i :80 yu ...