题意:给出树 求最大的sigma(a)/k k是选取的联通快个数   联通快不相交

思路: 这题和1个序列求最大的连续a 的平均值  这里先要满足最大平均值  而首先要满足最大  也就是一个数的时候可以找出最大值

满足第二个条件最长 也就是看最大值有多少个连续即可

而本题 也就是先找出最大值然后看直接先求出最大的一个联通快的max(sigma(a)) 然后算一共有多少个联通快等于这个最大的sigma即可

一开始还当dp做其实是个傻逼题。。

 #include<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
#define F first
#define S second
#define pii pair<int ,int >
#define mkp make_pair
#define pb push_back
#define arr(zzz) array<ll,zzz>
using namespace std;
typedef long long ll;
const int maxn=3e5+;
const int inf=0x3f3f3f3f;
int a[maxn];
struct Node{
int next,to;
}edge[maxn*];
int head[maxn];
int size=;
int n;
ll dp[maxn];
void add(int x,int y){
edge[size].to=y;
edge[size].next=head[x];
head[x]=size++;
}
ll ans=-inf;
ll dfs(int now,int fa){
ll sum=a[now];
for(int i=head[now];i!=-;i=edge[i].next){
int to=edge[i].to;
if(to!=fa){
sum=max(sum,sum+dfs(to,now));
}
}
ans=max(ans,sum);
return sum;
}
ll cnt=;
ll dfs2(int now,int fa){
ll sum=a[now];
for(int i=head[now];i!=-;i=edge[i].next){
int to=edge[i].to;
if(to!=fa){
sum=max(sum,sum+dfs2(to,now));
}
}
if(sum==ans)cnt++,sum=;
return sum;
}
int main(){
memset(head,-,sizeof(head));
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
for(int i=;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
add(x,y);
add(y,x);
}
dfs(,-);
dfs2(,-);
cout<<ans*cnt<<" "<<cnt<<endl;
return ;
}

Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学的更多相关文章

  1. Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem

    E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...

  2. Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem

    D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...

  3. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)

    参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...

  4. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(交互题 异或)

    题目 题意: 0≤a,b<2^30, 最多猜62次. 交互题,题目设定好a,b的值,要你去猜.要你通过输入 c d : 如果 a^c < b^d ,会反馈 -1 : 如果 a^c = b^ ...

  5. Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula

    F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树 ...

  6. Codeforces Round #525 (Div. 2)B. Ehab and subtraction

    B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减 ...

  7. Codeforces Round #525 (Div. 2)A. Ehab and another construction problem

    A. Ehab and another construction problem 题目链接:https://codeforc.es/contest/1088/problem/A 题意: 给出一个x,找 ...

  8. Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task 数学 mod运算的性质

    C. Ehab and a 2-operation task 数学 mod运算的性质 题意: 有两种对前缀的运算 1.对前缀每一个\(a +x\) 2.对前缀每一个\(a\mod(x)\) 其中x任选 ...

  9. Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task

    传送门 https://www.cnblogs.com/violet-acmer/p/10068786.html 题意: 给定一个长度为 n 的数组a[ ],并且有两种操作: ①将前 i 个数全都加上 ...

随机推荐

  1. Java语法 [开发环境搭建]

    自行百度. https://www.baidu.com 自行必应 https://cn.bing.com

  2. route命令详解

    1.   使用背景:需要接入两个网络,一个是部署环境所在内网环境,这个环境是上不了外网, 外网环境很可能是一个无线网络.如果两者都连接上,很可能导致有一方不能起作用,即外网或内网上不了,常常需要使用繁 ...

  3. ps命令详解

    1.简介: ps 命令有两种不同的语法风格 —— BSD 与 UNIX 两种风格.新手常常对这两种形式产生误解,因此我们有必要在这里作一个简单的说明: ps aux 与 ps -aux 是不同的,例如 ...

  4. Django+Vue.js框架快速搭建web项目

    一.vue环境搭建1.下载安装node.js.2.安装淘宝镜像cnpm,在命令窗口输入: npm install -g cnpm --registry=https://registry.npm.tao ...

  5. spark快速开发之scala基础之5高阶函数,偏函数,闭包

    高阶函数 高阶函数就是将函数作为参数或者返回值的函数. object function { def main(args: Array[String]): Unit = { println(test(f ...

  6. 20175314 《Java程序设计》迭代和JDB

    20175314 <Java程序设计>迭代和JDB 要求 1 使用C(n,m)=C(n-1,m-1)+C(n-1,m)公式进行递归编程实现求组合数C(m,n)的功能 2 m,n 要通过命令 ...

  7. Handler实现消息的定时发送

    话不多说,直接上代码 private Handler mHandler = new Handler() { @Override public void handleMessage(Message ms ...

  8. 169. Majority Element (Array)

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  9. 100-days: fourteen

    Title: Face mask craze(面膜热) creates Korean(韩国) (a) billionaire with Goldman(高盛集团) backing face mask ...

  10. 【开发工具】secureCRT的使用

    总结自己平时使用secureCRT中遇到的问题 1.安装 2.secureCRT设置标签显示远程主机ip地址