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.

证明:必定存在一条边数≤1的最优解

如果存在最优解(G)ans最小边数>1,则点数>2

ans=∑vi/∑c

由如果知对G的子图,(u+v)/c<ans ,(u+v)<ans*c

∴∑u+∑v<ans*∑c ,(∑u+∑v)/∑c<ans=∑vi/∑c

∴(∑u+∑v)<∑vi 矛盾

结论成立

所以仅仅要推断全部的仅仅取1条边,和不取的情况 O(m)

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iomanip>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (500+10)
#define MAXM (MAXN*MAXN)
#define MAXAi (1e6)
#define MAXCi (1e3)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
typedef long double ld;
int n,m,a[MAXN];
ld ans=0.0;
int main()
{
// freopen("Physics.in","r",stdin);
scanf("%d%d",&n,&m);
For(i,n) scanf("%d",&a[i]);
For(i,m)
{
int u,v;
double c;
scanf("%d%d%lf",&u,&v,&c);
ans=max(ans,(ld)(a[u]+a[v])/c);
}
cout<<setiosflags(ios::fixed)<<setprecision(100)<<ans; return 0;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

CF 444A(DZY Loves Physics-低密度脂蛋白诱导子图)的更多相关文章

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

    题目链接:Codeforces 444A 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 - 444A@ DZY Loves Physics

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

  4. cf444A DZY Loves Physics

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

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

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

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

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

  7. CF 445B DZY Loves Chemistry(并查集)

    题目链接: 传送门 DZY Loves Chemistry time limit per test:1 second     memory limit per test:256 megabytes D ...

  8. CF 444B(DZY Loves FFT-时间复杂度)

    B. DZY Loves FFT time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  9. Cf 444C DZY Loves Colors(段树)

    DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consi ...

随机推荐

  1. C++ 线程的创建,挂起,唤醒,终止

    例子: 线程代码: DWORD __stdcall ThreadProc(LPVOID lpParameter) { CMultiThreadDlg * pdlg = (CMultiThreadDlg ...

  2. magento后台登陆后,没任何提示,又跳转到登陆页面

    这个问题通常是cookie配置的问题.需要去将core_config_data中web/cookie/cookie_path.web/cookie/cookie_domain设为null

  3. Unity Easy Save简单实用

    Easy Save使用: 1.保存游戏进度        2.设计游戏关卡(怪物数量,坐标,背景图等等) Easy Save默认存储地址: C:\Users\Administrator\AppData ...

  4. Spring的AOP2

    本文是<AOP 那点事儿>的续集. 在上篇中,我们从写死代码,到使用代理:从编程式 Spring AOP 到声明式 Spring AOP.一切都朝着简单实用主义的方向在发展.沿着 Spri ...

  5. minicom与USB转串口

    实验器材:mini6410 连接方式:ARM板通过USB转串口线连接到pc机 下面是具体的设置了. 默认情况下,UBUNTU安装了USB转串口驱动(pl2303). 1.# lsmod | grep ...

  6. 《JavaScript 闯关记》之正则表达式

    由于本课程的核心是 JavaScript,所以本文着重讲解了「正则表达式」在 JavaScript 中的用法,并未深入「正则表达式」的具体细节.如果您尚不了解「正则表达式」,强烈推荐您先学习 正则表达 ...

  7. 求1+2+3+...+n的值,要求不能使用乘除法,for、while、if、else、switch、case、等关键字及条件判断语句(JAVA)

    采用递归和三目表达式注意红色字体一定不能写成n-- 1 package com.hunag; public class Sum { static int sum; public static int ...

  8. GoEasy实现web实时推送过程中的自动补发功能

    熟悉GoEasy推送的朋友都知道GoEasy推送实现web实时推送并且能够非常准确稳定地将信息推送到客户端.在后台功能中查看接收信息详情时,可有谁注意到有时候在发送记录里有一个红色的R标志?R又代表的 ...

  9. js编码规范

    使用统一的 编码规范 编写代码能提高JS代码的可读性,利于后期的维护和扩展,利于团队开发. 引用规范: 1.采用<script>...</script>方式引入 *.js 文件 ...

  10. 浅谈HTML5拖放

    现在,新增的HTML5元素很多,也给开发者带来了很多便利,比如说:结构标记header .nav.arctile.section.footer 表单元素:url.date.emaile.search. ...