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的更多相关文章
随机推荐
- Web前端:博客美化:一、模板美化
1.选用模板simplememory 2.写css放在 这些会覆盖掉原来的css样式 我是在网上找的css代码二次加工的 : ) /*1.针对simplememory的修改*/ #google_ad_ ...
- 通过 docker 来搭建 Jenkins
mkdir /data/jenkins -p mkdir /data/jenkins/{conf,data} -p echo "Asia/Shanghai" > /data/ ...
- C++语法小技巧
前言 写的很乱,各种内容都有.仅仅是为了记录一下 而且内容极其不严谨(没错,只有实践,没有理论)!请各位谨慎驾驶! 强制内联 #define Inline __inline__ __attribute ...
- CRM之分页
分页简介 分页功能在网页中是非常常见的一个功能,其作用也就是将数据分割成多个页面来进行显示. 使用场景: 当取到的数据量达到一定的时候,就需要使用分页来进行数据分割. 当我们不使用分页功能的时候,会面 ...
- C# 仿360悬浮球开发demo程序
https://files.cnblogs.com/files/wohexiaocai/%E4%BB%BF360%E5%8A%A0%E9%80%9F%E5%99%A8.zip
- Android注解神器 ButterKnife框架
前言: 本人是一个只有几个月工作经验的码小渣.这是我写的第一篇博客,如有不足之处还请大家不要介意,还请大佬可以指出问题. 在这几个月的实战开发中自己也遇到了很多问题,真的是举步艰难啊!!! 在实战开发 ...
- 【案例分享】crontab执行脚本异常问题
很多时候我们会遇见这种情况,我们千辛万苦写了一个脚本,经过测试,一切正常,然后放到了crontab里面执行,结果,不管怎么配置,就是执行不正常. 结果发现环境问题,居然是这个异常的元凶. 我们先在我们 ...
- Ubuntu下面MySQL的参数文件my.cnf浅析
前几天刚接手一个MySQL数据,操作系统为Ubuntu 16.04.5 LTS, 数据库版本为5.7.23-0ubuntu0.16.04.1(APT方式安装的MySQL).这个操作系统下的MySQL ...
- Chrome浏览器清除缓存
1.功能列表点击历史记录 可以是按时间清除 自动清除: 使用谷歌的无痕模式可以自动清除缓存
- tomcat设置开机启动
一.windows 1. 下载tomcat 2. 进入bin目录,查看是否存在service.dat,如果没有自行创建 3. 打开cmd,进入tomcat>bin目录 说明:用法: servic ...