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 ...
随机推荐
- 【PowerDesigner】【2】将工具栏显示出来
问题:我的软件一打开,没有工具栏 解决方案:Tools→Customize Menus and Tools→Palette→Close 参考文档: PowerDesigner如何将消失的工具栏显示出来 ...
- navicat 连接 mysql 解决出现client does not support authentication protocol requested by server的问题
MySQL8换了加密插件,数据库管理客户端都来不及更新,连接方式缺乏sha2的加密方式首先第一步, UPDATE mysql.user SET plugin = 'mysql_native_passw ...
- python-部分redis
数据量非常大时想向数据库中保存的时候,可以在中间加一个队列(队列的长度可以控制),可能数据库一个个取会效率慢一些,但是不会服务端不会蹦 redis: 端口6379 1.本质:向内存中存数据 2.对内存 ...
- 牛客练习赛30-A/C
链接:https://ac.nowcoder.com/acm/contest/216/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...
- 使用INTERSECT运算符
显示符合以下条件的雇员的雇员ID 和职务ID:这些雇员的当前职务与以前的职务相同,也就是说这些雇员曾担任过别的职务,但现在又重新担任了以前的同一职务. hr@TEST0924> SELECT e ...
- java正则中的requireEnd和hitEnd
package test; import java.util.regex.Matcher; import java.util.regex.Pattern; public class main { // ...
- C#实体对象序列化成Json并让字段的首字母小写的两种解决方法
引言:最近在工作中遇到与某些API对接的post的数据需要将对象的字段首字母小写.解决办法有两种:第一种:使用对象的字段属性设置JsonProperty来实现(不推荐,因为需要手动的修改每个字段的属性 ...
- zk 创建瞬时、顺序节点的原理
命令: create -s -e /worker/lock xx zk 的实现代码在:PrepRequestProcessor.pRequest2Txn 中 //The number of chang ...
- MySQL中的文件
查看数据目录: select @@datadir; 共享表空间: ibdata1 Redo log file:ib_logfile0, ib_logfile1 二进制日志:需要配置参数 server- ...
- vsftp的安装与配置
1.安装 直接使用yum安装,如果没有网络在其他机器使用yum先离线下载即可,vsftpd一般就自己不需要装其他依赖包 rpm -qa|grep vsftpd #查看是否安装 yum install ...