hdu6090 菊花图
Rikka with Graph
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 239 Accepted Submission(s): 157
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)
.
, the number of the testcases.
For each testcase, the first line contains two numbers n,m(1≤n≤106,1≤m≤1012)
.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int T;
for(scanf("%d",&T); T--;)
{
long long n,m;
scanf("%I64d%I64d",&n,&m);
long long maxx=n*(n-)/;
if(m>=maxx) printf("%I64d\n",maxx*);
else if(m>=n-) printf("%I64d\n",*(n-)*(n-)-*(m-n+));
else printf("%I64d\n",*m*m+(n-m-)*(m+)*n*+(n-m-)*(n-m-)*n);
}
}
hdu6090 菊花图的更多相关文章
- CF981C(菊花图)
题目描述 RAMESS知道很多关于树的问题(无循环的无向连通图)! 他创建了一个新的有用的树的划分,但他不知道如何构造它,所以他请求你的帮助! 划分是从树上的边中分裂出一些简单的路径,使得每个两条路径 ...
- CF GYM 100781A(菊花图+直径)
题目大意 给出若干颗树用最少的边把它们连成一个无向连通图,同时使图的直径最小.输出最小直径. 题解 我们定义树的半径为(树的直径+1)/2.符合题意的连接方式为.所有树的“中点”连在直径最长的树的中点 ...
- bzoj1023: [SHOI2008]cactus仙人掌图
学习了一下圆方树. 圆方树是一种可以处理仙人掌的数据结构,具体见这里:http://immortalco.blog.uoj.ac/blog/1955 简单来讲它是这么做的:用tarjan找环,然后对每 ...
- 【构造】【贪心】hdu6090 Rikka with Graph
给你n个点,让你连m条边,使得任意两两点对之间的最短路的和最小(两点若不可达,最短路记作n). 初始时ans=n*n*(n-1). 先尽量连成菊花图,每连一次让答案减小2*((n-2)*(i-1)+( ...
- [ZJOI 2018] 线图
别想多了我怎么可能会正解呢2333,我只会30分暴力(好像现场拿30分已经不算少了2333,虽然我局的30分不是特别难想). 首先求k次转化的点数显然可以变成求k-1次转化之后的边数,所以我们可以先让 ...
- BZOJ 4289 最短路+优化建图
题意:给出一个N个点M条边的无向图,经过一个点的代价是进入和离开这个点的两条边的边权的较大值,求从起点1到点N的最小代价.起点的代价是离开起点的边的边权,终点的代价是进入终点的边的边权. 解法:参考h ...
- 【SDOI2017】天才黑客(前后缀优化建图 & 最短路)
Description 给定一张有向图,\(n\) 个点,\(m\) 条边.第 \(i\) 条边上有一个边权 \(c_i\),以及一个字符串 \(s_i\). 其中字符串 \(s_1, s_2, \c ...
- BZOJ 3784: 树上的路径
Description 问一棵树上前 \(k\) 大路径的边权. Sol 边分治. 非常感谢数据没有菊花图. 为了写写边分治试试然后就开了这道题. 边分治非常好想,选一条重边,分成两部分,然后分别求最 ...
- [NOIP2014]自测
这两天做完了2014年的noip提高. 因为以前看了SDSC2016时gty的课件,题目思路都知道了一点,做起来没多大困难. 100+100+75+100+100+70=545 里面水分好多,好多题都 ...
随机推荐
- 配置路由器/交换机的Telnet登录
实验目的:给配置路由器/交换机管理IP地址.设置Telnet的登录帐号.密码. 第一步:配置路由器的名称.接口IP地址. Switch> Switch>en Switch# Switch# ...
- SDN 是什么
SDN,Software Defined Network,软件定义(的)网络,这些年方兴未艾,愈演愈烈.但是,笔者以为,SDN 也有愈演愈劣的趋势.而且,现在业界关于什么叫 SDN,也是众说纷坛,莫衷 ...
- python笔记 函数初识
1. 函数: 封装一个功能 def my_len(形参): -> def 声明定义一个函数 my_len 函数名命名规则同变量 ······ - ...
- bfs—迷宫问题—poj3984
迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20591 Accepted: 12050 http://poj ...
- JVM调优方法笔记
1.性能工具介绍 jvisualvm jmap jstat jstack/threaddump jprofiler jmeter 2.性能调优4步骤 重现问题 定位问题 模拟问题 解决问题 http: ...
- Linked List-2
三.编码技巧 1.遍历链表 先将head指针赋值给一个局部变量current: //return the number of nodes in a list (while-loop version) ...
- vue 遮罩层阻止默认滚动事件
vue中提供 @touchmove.prevent 方法可以完美解决这个问题. <div class="child" @touchmove.prevent ></ ...
- 「newbee-mall新蜂商城开源啦」 前后端分离的 Vue 版本即将开源
新蜂商城 Vue 版本 2019 年 10 月份我在 GitHub 开源仓库中上传了新蜂商城项目的所有源码,至今已经有小半年的时间了,感兴趣的可以去了解一下这个 Spring Boot 技术栈开发的商 ...
- A Simple Problem with Integers 循环节 修改 平方 找规律 线段树
A Simple Problem with Integers 这个题目首先要打表找规律,这个对2018取模最后都会进入一个循环节,这个循环节的打表要用到龟兔赛跑. 龟兔赛跑算法 floyed判环算法 ...
- Pycharm修改HTML模板
