题意:给出树 求最大的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. Swift get和set方法以及只读属性(计算型属性,本身不保存数据,都是通过计算获得结果)

    import UIKit class Person: NSObject { private var _name: String? var name: String? { get { return _n ...

  2. proposal-cancelable-promises

    fetch 从来就没行过,最大的优势就是"新标准",但是 proposal-cancelable-promises 被 withdrawn,就导致了 fetch 发起的请求不可能被 ...

  3. SSM商城项目(六)

    1.学习计划 1.Redis服务器搭建 2.Redis持久化 3.Redis集群搭建 4.Jedis 5.Solr服务器安装 2.Redis的安装 2.1. Redis的安装 Redis是c语言开发的 ...

  4. 详细分析MySQL事务日志(redo log和undo log) 表明了为何mysql不会丢数据

    innodb事务日志包括redo log和undo log.redo log是重做日志,提供前滚操作,undo log是回滚日志,提供回滚操作. undo log不是redo log的逆向过程,其实它 ...

  5. RESTful API格式 图片验证码接口

    之前公司写图片验证码时用的是session 后来写接口时也想用session存验证码  不过领导说RESTful API 写接口 没有session这一说 于是就用了redis 存验证码 还有就是接口 ...

  6. "Web Scraping with Python"笔记(一)

    1.  合法性:抓取的数据用于个人使用,不存在问题:数据用于转载,需注意抓取的数据类型. 一般情况,抓取的真实数据(营业地址,电话清单等)允许转载.而原创数据(比如意见和评论)受版权限制不能转载. 2 ...

  7. Linux 禁止普通用户su到root

    Linux账户权限管理上为了防止普通用户通过su切换到root用户,需要修改/etc/pam.d/su和/etc/login.defs两个配置文件. Step1:修改 /etc/pam.d/su文件 ...

  8. 419. Battleships in a Board 棋盘上的战舰数量

    [抄题]: Given an 2D board, count how many battleships are in it. The battleships are represented with  ...

  9. Java 后台验证的工具类

    Java 后台验证的工具类 public class ValidationUtil {         //手机号     public static String mobile = "^( ...

  10. 设计模式学习心得<工厂方法 Factory Method>

    概述 意图 业务代码中常常有构造对象的过程,它拥有大量的参数.并且有很多地方需要这对象. 简化对象构造过程. 主要解决 一个类在不同场景的频繁地创建,让不同对象的创建更有语义化,提高代码复用性. 何时 ...