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的更多相关文章
随机推荐
- Fundebug发布Vue插件,简化BUG监控接入代码
摘要: 代码越短越好! 我们发布了fundebug-vue插件,可以简化Vue框架接入Fundebug的代码. Vue如何接入Fundebug 1. 安装fundebug-javascript与fun ...
- vuex最详细完整的使用用法
来自:https://blog.csdn.net/qq_35430000/article/details/79412664#commentBox github仓库地址:https://github. ...
- CTSC 2018酱油记
Day0 5.5 花了一上午的时间把codechef div2的前四题切了,又在zbq老司机的指导下把第五题切了 中午12:00 gryz电竞组从机房出发,临走的时候看到很多学长挺恋恋不舍的,毕竟可能 ...
- JavaScript(二)
本文转载自https://blog.csdn.net/xiaogeldx/article/details/85412716 JavaScript操作符 算术运算符 算术运算符有:+,-,*,/,%,+ ...
- MAC终端常用语法
这篇文章的重点不在于说是对终端语法的讲解,而是方便大家做语法备忘. 方便查找对应终端语法.所以使用了表格形式对常用终端语法进行了汇总, 但是并没有很多的讲解部分. 当然了这里记录的也都是十分基础的语法 ...
- Monkey测试记录
配置环境变量,不然用不了adb命令 path这里也一样配置一下 命令的各种意思百度一下看看也就知道了 看到一篇博客推荐的一种测试命令,我也直接拿来用了 adb shell monkey -p 你的包名 ...
- PJSUA2开发文档--第三章 PJSUA2高级API
3. PJSUA2高级API PJSUA2是PJSUA API以上的面向对象抽象.它为构建会话发起协议(SIP)多媒体用户代理应用程序(也称为IP / VoIP软电话)提供高级API.它将信令,媒体和 ...
- c/c++ 多线程 等待一次性事件 异常处理
多线程 等待一次性事件 异常处理 背景:假设某个future在等待另一个线程结束,但是在被future等待的线程里发生了异常(throw一个异常A),这时怎么处理. 结果:假设发生了上面的场景,则在调 ...
- Python Learning: 01
After a short period of new year days, I found life a little boring. So just do something funny--Py ...
- 在java web项目中实现随项目启动的额外操作
前言 在web项目中经常会遇到在项目启动初始,会要求做一些逻辑的实现,比如实现一个消息推送服务,实现不同类型数据同步的回调操作初始化,或则通知其他客户服务器本项目即将启动,等等.对于这种要求,目前个人 ...