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

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)

(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)

.

 
Input
The first line contains a number t(1≤t≤10)

, the number of the testcases.

For each testcase, the first line contains two numbers n,m(1≤n≤106,1≤m≤1012)

.

 
Output
For each testcase, print a single line with a single number -- the answer.
 
Sample Input
1
4 5
 
Sample Output
14

#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 菊花图的更多相关文章

  1. CF981C(菊花图)

    题目描述 RAMESS知道很多关于树的问题(无循环的无向连通图)! 他创建了一个新的有用的树的划分,但他不知道如何构造它,所以他请求你的帮助! 划分是从树上的边中分裂出一些简单的路径,使得每个两条路径 ...

  2. CF GYM 100781A(菊花图+直径)

    题目大意 给出若干颗树用最少的边把它们连成一个无向连通图,同时使图的直径最小.输出最小直径. 题解 我们定义树的半径为(树的直径+1)/2.符合题意的连接方式为.所有树的“中点”连在直径最长的树的中点 ...

  3. bzoj1023: [SHOI2008]cactus仙人掌图

    学习了一下圆方树. 圆方树是一种可以处理仙人掌的数据结构,具体见这里:http://immortalco.blog.uoj.ac/blog/1955 简单来讲它是这么做的:用tarjan找环,然后对每 ...

  4. 【构造】【贪心】hdu6090 Rikka with Graph

    给你n个点,让你连m条边,使得任意两两点对之间的最短路的和最小(两点若不可达,最短路记作n). 初始时ans=n*n*(n-1). 先尽量连成菊花图,每连一次让答案减小2*((n-2)*(i-1)+( ...

  5. [ZJOI 2018] 线图

    别想多了我怎么可能会正解呢2333,我只会30分暴力(好像现场拿30分已经不算少了2333,虽然我局的30分不是特别难想). 首先求k次转化的点数显然可以变成求k-1次转化之后的边数,所以我们可以先让 ...

  6. BZOJ 4289 最短路+优化建图

    题意:给出一个N个点M条边的无向图,经过一个点的代价是进入和离开这个点的两条边的边权的较大值,求从起点1到点N的最小代价.起点的代价是离开起点的边的边权,终点的代价是进入终点的边的边权. 解法:参考h ...

  7. 【SDOI2017】天才黑客(前后缀优化建图 & 最短路)

    Description 给定一张有向图,\(n\) 个点,\(m\) 条边.第 \(i\) 条边上有一个边权 \(c_i\),以及一个字符串 \(s_i\). 其中字符串 \(s_1, s_2, \c ...

  8. BZOJ 3784: 树上的路径

    Description 问一棵树上前 \(k\) 大路径的边权. Sol 边分治. 非常感谢数据没有菊花图. 为了写写边分治试试然后就开了这道题. 边分治非常好想,选一条重边,分成两部分,然后分别求最 ...

  9. [NOIP2014]自测

    这两天做完了2014年的noip提高. 因为以前看了SDSC2016时gty的课件,题目思路都知道了一点,做起来没多大困难. 100+100+75+100+100+70=545 里面水分好多,好多题都 ...

随机推荐

  1. VR全景视图 Google VrPanoramaView

    2019独角兽企业重金招聘Python工程师标准>>> 一.背景简介 Welcome to VR at Google 进入Google VR主页,发现官方给我们提供了两套解决观看VR ...

  2. for-loop 与 json.Unmarshal 性能分析概要

    原文地址:for-loop 与 json.Unmarshal 性能分析概要 前言 在项目中,常常会遇到循环交换赋值的数据处理场景,尤其是 RPC,数据交互格式要转为 Protobuf,赋值是无法避免的 ...

  3. xml文件错误

    2019独角兽企业重金招聘Python工程师标准>>> xml文件错误The processing instruction target matching "[xX][mM ...

  4. 精确计算微信小程序scrollview高度,全机型适配

    众所周知,可以滑动的 scroll 组件在移动端非常的重要,几乎每个页面都要用到. 而小程序的 scroll-view 组件就比较坑了,非得指定一个高度才能正常使用.布局复杂的时候谁还给你算高度啊.. ...

  5. MySQL UDF Dynamic Library Exploit in *nix

    /* } 本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/575448,如需转载请自行联系原作者

  6. winform练习-通过遍历Control容器中的对象统一委托事件-楼盘选择器

    1.窗体布局如下,一个label标签内容如下,一个btnSave按钮,用于保存,其他九个按钮用于选择楼盘. 2. 按钮存于Control容器中,编写方法遍历容器中的button,通过条件过滤掉不是bu ...

  7. CentOS 7 网络优化(升级内核、开启 BBR)

    我之前介绍过关于 TCP 一些优化,包括安装使用 TCP 优化软件,这些适用于较低版本的 CentOS 系统,例如 CentOS 6,详细可参考<Linux 下的一些简单的 TCP 优化> ...

  8. DeepWalk论文精读:(1)解决问题&相关工作

    模块1 1. 研究背景 随着互联网的发展,社交网络逐渐复杂化.多元化.在一个社交网络中,充斥着不同类型的用户,用户间产生各式各样的互动联系,形成大小不一的社群.为了对社交网络进行研究分析,需要将网络中 ...

  9. 更安全的rm命令,保护重要数据

    更安全的rm命令,保护重要数据 网上流传的安全的rm,几乎都是提供一个rm的"垃圾"回收站,在服务器环境上来说,这实非良方. 我想,提供一个安全的rm去保护一些重要的文件或目录不被 ...

  10. CentOS安装配置nginx和php

    今天买了台阿里云服务器用于日常开发测试(新人9块钱半年).系统版本CentOS 6.5 64位. 首先安装nginx: yum install nginx 参考文档: 在CentOS 6上搭建LNMP ...