题目链接: 传送门

DZY Loves Chemistry

time limit per test1 second     memory limit per test256 megabytes

Description

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, m represents the number of edges.
The second line contains n space-separated integers xi (1 ≤ xi ≤ 10^6), 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 ≤ 10^3), 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 Input

1 0
1

2 1
1 2
1 2 1

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

Sample Output

0.000000000000000

3.000000000000000

2.965517241379311

思路:

题目大意:给出一张图,图中的每个节点,每条边都有一个权值,现在有从中挑出一张子图,要求子图联通,并且被选中的任意两点,如果存在边,则一定要被选中。问说点的权值和/边的权值和最大是多少。
可以证明,密度最大的子图一定只有两个点,再往里面加任何边,密度都会被拉低。
假设一个图现在有两个点点权为v1,v2,他们之间相连的边的边权为m1,该图的密度为(v1+v2)/m1。如果增加一个点v3要让该图的密度增加,若v3与v2相连的边的边权为m2。那么只有与v3/m2>(v1+v2)/m1,该图的密度才会增加。但是此时,v2与v3两个点构成的子图的密度为(v2+v3)/m2>(v1+v2+v3)/(m1+m2)。所以密度最大的子图一定只有两个点。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef __int64 LL;

int main()
{
    int N,M;
    while (~scanf("%d%d",&N,&M))
    {
        double ans[505] = {0};
        int u,v,val;
        double res = 0;
        for (int i = 1;i <= N;i++)
        {
            scanf("%lf",&ans[i]);
        }
        while (M--)
        {
            scanf("%d%d%d",&u,&v,&val);
            res = max (res,(ans[u]+ans[v])/val);
        }
        printf("%.15lf\n",res);
    }
    return 0;
} 

CF 444C DZY Loves Physics(图论结论题)的更多相关文章

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

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

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

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

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

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

  4. Codeforces 444C DZY Loves Colors(线段树)

    题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...

  5. cf444A DZY Loves Physics

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

  6. CF 444A(DZY Loves Physics-低密度脂蛋白诱导子图)

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

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

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

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

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

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

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

随机推荐

  1. 使用socket()函数创建套接字

    在Linux中,一切都是文件,除了文本文件.源文件.二进制文件等,一个硬件设备也可以被映射为一个虚拟的文件,称为设备文件.例如,stdin 称为标准输入文件,它对应的硬件设备一般是键盘,stdout ...

  2. 十天冲刺---Day3

    站立式会议 站立式会议内容总结: git上Issues新增内容: 燃尽图 照片 组长情绪爆炸是很可怕的事情.这里自责一下. 进度缓慢是一件非常头疼的事情.还有每个人的时间都很紧张,除了学习,还有各种工 ...

  3. Java反射机制学习与研究

    Java反射机制:可以获取正在运行时的Java对象. 1.判断运行时对象对象所属的类. 2.判断运行时对象所具有的成员变量和方法. 3.还可以调用到private方法,改变private变量的值. S ...

  4. 用Okhttp框架登录之后的Cookie设置到webView中(转)

    1.webview中设置: [java] view plain copy @SuppressWarnings("deprecation") public void synCooki ...

  5. Linux下C++静态库、动态库的制作与使用

    参考博文:C++静态库与动态库 >> 静态库 1. 静态库的制作 a) 编辑 name.cpp 和name.h文件 b) $g++ -c name.cpp //注意带参数-c,否则直接编译 ...

  6. Servlet作业2-将表单提交的商品信息输出到页面中

    1,表单页面 shangpin.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...

  7. iOS开发--录音简单实现

  8. ps制作gif图片

    本文自学内容来自这里 PS版本是CS6: 制作效果 步骤 1.下载素材 2.打开ps,添加素材 文件->打开->选择所有需要的素材全部打开(如图,已将需要的3个素材全部打开) 3.将素材放 ...

  9. 提示reg不是批处理命令怎么办

    'regsvr32' 不是内部或外部命令,也不是可运行的程序或批处理文件.请按任意键继续. . . 系统环境变量被改了进入控制面板>高级>环境变量>系统变量,Path双击一下,填入C ...

  10. 控件(文本类): AutoSuggestBox

    Controls/TextControl/AutoSuggestBoxDemo.xaml <Page x:Class="Windows10.Controls.TextControl.A ...