codeforces444A
DZY Loves Physics
DZY loves Physics, and he enjoys calculating density.
Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows:
where v is the sum of the values of the nodes, e is the sum of the values of the edges.
Once DZY got a graph G, now he wants to find a connected induced subgraph G' of the graph, such that the density of G' is as large as possible.
An induced subgraph G'(V', E') of a graph G(V, E) is a graph that satisfies:
;
- edge
if and only if
, and edge
;
- the value of an edge in G' is the same as the value of the corresponding edge in G, so as the value of a node.
Help DZY to find the induced subgraph with maximum density. Note that the induced subgraph you choose must be connected.
Input
The first line contains two space-separated integers n (1 ≤ n ≤ 500), . Integer n represents the number of nodes of the graph G, mrepresents the number of edges.
The second line contains n space-separated integers xi (1 ≤ xi ≤ 106), where xirepresents the value of the i-th node. Consider the graph nodes are numbered from 1to n.
Each of the next m lines contains three space-separated integers ai, bi, ci (1 ≤ ai < bi ≤ n; 1 ≤ ci ≤ 103), denoting an edge between node ai and bi with value ci. The graph won't contain multiple edges.
Output
Output a real number denoting the answer, with an absolute or relative error of at most 10 - 9.
Examples
1 0
1
0.000000000000000
2 1
1 2
1 2 1
3.000000000000000
5 6
13 56 73 98 17
1 2 56
1 3 29
1 4 42
2 3 95
2 4 88
3 4 63
2.965517241379311
Note
In the first sample, you can only choose an empty subgraph, or the subgraph containing only node 1.
In the second sample, choosing the whole graph is optimal.
sol:超有趣的结论题。
结论:答案肯定是一个最多只有一条边的子图;
证明:在已经有两个点的一张子图中,如果加入一个新点会使得答案更优,那么肯定新点和两个点其中一个或图中一个点比三个点的更优
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m;
double Quanz[N];
int main()
{
int i;
double ansV=,ansE=;
R(n); R(m);
for(i=;i<=n;i++) R(Quanz[i]);
for(i=;i<=m;i++)
{
int x,y;
double z;
R(x); R(y); R(z);
if((ansE==)||(double)(ansV/ansE)<(double)(Quanz[x]+Quanz[y])/z)
{
ansV=Quanz[x]+Quanz[y]; ansE=z;
}
}
if(ansE==) puts("0.00000000000000000");
else printf("%.17lf\n",ansV/ansE);
return ;
}
/*
Input
1 0
1
Output
0.000000000000000 Input
2 1
1 2
1 2 1
Output
3.000000000000000 Input
5 6
13 56 73 98 17
1 2 56
1 3 29
1 4 42
2 3 95
2 4 88
3 4 63
Output
2.965517241379311
*/
codeforces444A的更多相关文章
随机推荐
- 前端入门19-JavaScript进阶之闭包
声明 本系列文章内容全部梳理自以下几个来源: <JavaScript权威指南> MDN web docs Github:smyhvae/web Github:goddyZhao/Trans ...
- 【代码笔记】Web-CSS-CSS background背景
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- XSS Challenges
平台: http://www.zixem.altervista.org/XSS/ level1: Payload: http://www.zixem.altervista.org/XSS/1.php? ...
- 设置Editext的光标宽高与颜色
在Editext的布局属性上加上 android:textCursorDrawable="@drawable/cursor_shape" cursor_shape如下: <? ...
- C# 动态生成word文档
本文以一个简单的小例子,简述利用C#语言开发word表格相关的知识,仅供学习分享使用,如有不足之处,还请指正. 在工程中引用word的动态库 在项目中,点击项目名称右键-->管理NuGet程序包 ...
- 使用OkHttp和Retrofit发送网易云信验证码
短信服务(Short Message Service)是网易网易云通信为用户提供的一种通信服务的能力,目前支持验证码类短信.通知类短信.运营类短信.语音类短信.国际短信等事务性短信.网易网易云通信短信 ...
- Hasse神舟笔记本卡logo解决,刷BIOS方法,教你修复神船
我的电脑是神舟战神K660E i7 d7的,前两天装Windows10,Ubuntu,MAC OS Mojave,PE 一堆操作,使用bootice重建uefi引导,结果在前几天,我删了一个重复的ue ...
- Kafka相关内容总结(存储和性能)
Kafka消息的存储 Kafka的设计基于一种非常简单的指导思想:不是要在内存中保存尽可能多的数据,在需要时将这些数据刷新(flush)到文件系统,而是要做完全相反的事情.所有数据都要立即写入文件系统 ...
- rpc接口调用以太坊智能合约
rpc接口调用以太坊智能合约 传送门: 柏链项目学院 在以太坊摸爬滚打有些日子了,也遇到了各种各样的问题.这几天主要研究了一下如何通过rpc接口编译.部署和调用合约.也遇到了一些困难和问题,下面将 ...
- VS2015 IIS Express Web服务器无法启动解决办法
1.运行和调试vs2015项目 提示无法运行项目,打开vs2013项目发现可以正常运行,所以推测试vs2015项目配置有问题. 2.找到项目启动项中 .csproj文件,定位到<WebProje ...