A. 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.

lwh大神说,这不是01分数规划吗,二分+网络流!

我吓坏了

结果事实证明ccr代码竟然真A了

贪心证明略(废话我当然不知道怎么证)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int x[1000001];
int main()
{
int n, m;
cin >> n >> m;
double ans = 0;
int p, q, c;
for (int i = 1; i<= n; i++)
cin >> x[i];
for (int i = 0; i< m; i++)
{
cin >> p >> q >> c;
ans = max(ans, (double) (x[p] + x[q]) / c);
}
printf("%.10f", ans);
}

cf444A DZY Loves Physics的更多相关文章

  1. CF444A DZY Loves Physics【结论】

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

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

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

  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

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

  7. 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+\ ...

  8. 【Codeforces 444A】DZY Loves Physics

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

  9. @codeforces - 444A@ DZY Loves Physics

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 点 m 边的图,边有边权,点有点权. 找到一个连通 ...

随机推荐

  1. PHP字符串左边补0,字符串右边补0

    概述:项目中经常会使用到在一串编码左边.右边甚至中间自动填充制定字符如"0" 并且制定填充后的字符串长度. 函数str_pad:该函数返回 input 被从左端.右端或者同时两端被 ...

  2. Linux安装mysql-python库时报错解决办法

    用pip安装mysql-python库的时候遇到如下报错 root@LoidAir:~# pip install mysql-python Collecting mysql-python Using ...

  3. ApacheBench~网站性能测试工具

    对于网站性能测试来说,一般我们会使用loadrunner来实现,而它过于庞大,使我们感到有些不爽,而今天介绍的ApacheBench工具,它小而精,使用简单,效果直观,可以说,是比lr更好用的性能测试 ...

  4. TTTAttributedLabel使用介绍(转)

    TTTAttributedLabel 库地址 https://github.com/TTTAttributedLabel/TTTAttributedLabel 可以实现电话  地址  链接自动查找显示 ...

  5. 关于ionic的一些坑(1)

    既然来了,总要留下点什么证明自己来过不是,今天就扒一扒自己在ionic上面遇到的坑,因为在项目中2还没出来,所以现在所遇到的都是1中的,关于2的,待老夫以后详细摸索之后在与君细细道来. 1.ionic ...

  6. 怎样把HTC G7的内存扩展到2GB

    介绍 HTC G7的内部存储只有148M,两年前买它的时候,android应用大多比较小巧,148M已经足够用了.随着android版本的不断升级,应用变得越来越臃肿,G7也变得越来越吃力.就我个人而 ...

  7. [置顶] NO.4 使用预处理器进行调试

    <c++ primer>第四版 p190 ************************************************************************* ...

  8. iOS蓝牙4.0协议简单介绍

    iOS开发蓝牙4.0的框架是CoreBluetooth,本文主要介绍CoreBluetooth的使用,关于本文中的代码片段大多来自github上的一个demo,地址是myz1104/Bluetooth ...

  9. this——笔记

    this是执行上下文中的一个属性.this与上下文中可执行代码的类型有直接关系,this值在进入上下文时确定,并且在上下文运行期间永久不变. 在这里一切都简单.在全局代码中,this始终是全局对象本身 ...

  10. Code First研究学习2_基本的错误及解决方法

    使用Code First时总有很多的问题出现,以下列举了一些基本的错误及解决方法! 1.当用Enable-Migrations启动数据库迁移后,如果再继续输入Enable-Migrations命令,则 ...