DZY Loves Physics
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 Gm represents
the number of edges.

The second line contains n space-separated integers xi (1 ≤ xi ≤ 106),
where xi represents
the value of the i-th node. Consider the graph nodes are numbered from 1 to 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.

Sample test(s)
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
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.

解题报告

这题的优先策略是仅仅选一条边。

(v+a)/(e+b)  <=  v/e

#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,num[550];
int main()
{
int u,v,w,i,j;
while(cin>>n>>m)
{
memset(num,0,sizeof(num));
double maxx=0;
for(i=1;i<=n;i++)
{
cin>>num[i];
}
for(i=0;i<m;i++)
{
cin>>u>>v>>w;
maxx=max(maxx,(num[u]+num[v])/(double)w);
}
printf("%.15lf\n",maxx);
}
}

Codeforces444A_DZY Loves Physics的更多相关文章

  1. CF 444C DZY Loves Physics(图论结论题)

    题目链接: 传送门 DZY Loves Chemistry time limit per test1 second     memory limit per test256 megabytes Des ...

  2. cf444A DZY Loves Physics

    A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #254 (Div. 1) A. DZY Loves Physics 智力题

    A. DZY Loves Physics 题目连接: http://codeforces.com/contest/444/problem/A Description DZY loves Physics ...

  4. CodeForces 444C. DZY Loves Physics(枚举+水题)

    转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207 题目链接:http://codeforces.com/contest/ ...

  5. Codeforces 444A DZY Loves Physics(图论)

    题目链接:Codeforces 444A DZY Loves Physics 题目大意:给出一张图,图中的每一个节点,每条边都有一个权值.如今有从中挑出一张子图,要求子图联通,而且被选中的随意两点.假 ...

  6. BZOJ3570 : DZY Loves Physics I

    考虑两个质量均为m,速度分别v1.v2的小球发生完全弹性碰撞的影响: 由动能守恒得: $\frac{1}{2}mv_1^2+\frac{1}{2}mv_2^2=\frac{1}{2}mv_1'^2+\ ...

  7. 【权值分块】bzoj3570 DZY Loves Physics I

    以下部分来自:http://www.cnblogs.com/zhuohan123/p/3726306.html 此证明有误. DZY系列. 这题首先是几个性质: 1.所有球质量相同,碰撞直接交换速度, ...

  8. 【Codeforces 444A】DZY Loves Physics

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 两个点的子图他们的"密度"是比所有联通生成子图都要大的 "只要胆子大,遇到什么问题都不怕!" [代码] ...

  9. CF444A DZY Loves Physics【结论】

    题目传送门 话说这道题不分析样例实在是太亏了...结论题啊... 但是话说回来不知道它是结论题的时候会不会想到猜结论呢...毕竟样例一.二都有些特殊. 观察样例发现选中的子图都只有一条边. 于是猜只有 ...

随机推荐

  1. @RequestBody接收的是一个json对象

    一直以为在SpringMVC环境中,@RequestBody接收的是一个json对象,调试代码时没有成功,后来才发现,其实 @RequestBody接收的是一个json字符串,而不是一个json对象. ...

  2. go之for循环

    一.基于计数器的迭代 格式 for 初始化语句; 条件语句; 修饰语句{} 实例 package main import "fmt" func main(){ for i:=0;i ...

  3. html body中的标签2

    一.列表标签 列表标签分为三种. 1.无序列表<ul>,无序列表中的每一项是<li> 英文单词解释如下: ul:unordered list,“无序列表”的意思. li:lis ...

  4. MVC异步上传图片到本地/服务器

    这两天朋友问我,有没有异步上传图片到本地/服务器这种demo,他有用, 我就想,好吧, 那刚好周末了,整理一套出来. 主要用到的是jquery uploadify 这个juqery的插件 ,可以无刷新 ...

  5. jsp页面导入excel文件的步骤及配置

    上传使用flash插件 需要jquery.uploadify.min.js,uploadify.css,poi-ooxml-3.8-20120326.jar等 jsp页面: <%@include ...

  6. Python yield解析

    Pyhton generators and the yield keyword At a glance,the yield statement is used to define generators ...

  7. android中复制图片

    activity_main.xml中的配置 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...

  8. 【PostgreSQL-9.6.3】如何实现非自动提交

    我们在使用psql工具操作数据库时,事务是自动提交的.也就是说,当我们执行完一条insert或者delete语句后,在不输入commit情况下,这条语句也是提交的.如果不想自动提交,可以使用以下两种方 ...

  9. 基于 CC2530 的温度采集系统(未定稿)

    前言 最近在自学 Zigbee,每天的主要是任务是:看博客,看 CC2530 的 datasheet 和实践,熟悉片上的 SFR 以及控制板子. 学和做内容包括:IO.外部中断.Timer1/3/4. ...

  10. 小程序viewflex布局的对齐不对的问题

    index.wxml: <view class="container"> <view class="nav-container"> &l ...