有关图的密度的规律

题目是这样的:
Description:
这里写图片描述
这里写图片描述

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 ≤ 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.
这里写图片描述

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

解题的思路来自:
这里写图片描述

所以只需找到两个点中密度最大的即可!

代码如下:

#include <iostream>
#include <cstdio>
using namespace std;
int a[505];
int main()
{
    int n,m;
    int n1,n2;
    double max=0;
    int v;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    if(n==1)
    {
        cout<<0.000000000000000<<endl;
        return 0;
     } 
    for(int j=0;j<m;j++)
    {
        cin>>n1>>n2>>v;
        double n3= (double)(a[n1]+a[n2])/v;
        if(n3>max)
        {
            max=n3;
        }
    }
    printf("%.15lf",max);
    return 0;
}

仅代表个人观点,欢迎交流探讨,勿喷~~~

这里写图片描述

PhotoBy:WLOP

http://weibo.com/wlop

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值