Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学
题意:给出树 求最大的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 数学的更多相关文章
- 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 题意: 给出一个 ...
- 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 ...
- 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/ ...
- 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^ ...
- 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 题意: 给出一颗点有权值的树 ...
- Codeforces Round #525 (Div. 2)B. Ehab and subtraction
B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减 ...
- 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,找 ...
- 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任选 ...
- Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task
传送门 https://www.cnblogs.com/violet-acmer/p/10068786.html 题意: 给定一个长度为 n 的数组a[ ],并且有两种操作: ①将前 i 个数全都加上 ...
随机推荐
- 用ActiveX 创建自己的comboBox 控件(一)
新建ActiveX工程ActiveXcomboBox Ok->next->next->next, create control based on 选择combobox, ...
- test case VS test scenario
---恢复内容开始--- 1. test case: how to test --如何测试 test scenario: what to be tested --测试什么 2. test scen ...
- logrotate-日志切割示例
logrotate是linux系统自带的工具,它可以自动对日志进行截断(或轮循).压缩以及删除旧的日志文件. 1)配置文件示例# cat /wls/wls81/bin/weblogic/wls/app ...
- python的arp扫描
python的arp扫描 from optparse import *from scapy.all import *parser = OptionParser()parser.add_option(& ...
- m3u8文件什么合成便于播放的MP4的方法
先大家要知道M3U8文件不是一个视频文件,里面全是一些路径,说白了就是一个目录而已,所以要看视频,要找到对应存放视频的文件夹.如果不知道怎么找,可以使用文本格式打开M3U8文件,里面会有路径提示. ...
- C#之SByte
int8 C#中,byte为无符号8位整数,而Sbyte为有符号8位整数,对应java中的byte类型. 方法一将 byte 转为 sbyte.原理很简单,就是当 byte 小于 128 时其值保持不 ...
- CentOS7配置samba服务
Step1:安装samba相关软件 [root@node-1 ~]# yum -y install samba samba-client Step2:创建共享目录 [root@node-1 ~]# m ...
- 100-days: seventeen
Title: How 'Bohemian Rhapsody(波西米亚狂想曲)' ended up in 'Wayne's World(反斗智多星)' and became a phenomenon(现 ...
- c#: Label控件加入AutoHeight属性
此功能在界面布局中颇为实用,录代码以记之: public class LabelEx : Label { private bool autoHeight = true; [DefaultValue(t ...
- pythone函数基础(9)操作数据库连接
#操作数据库连接import pymysqlconn = pymysql.connect(host='118.24.3.40',user='jxz', password='123456',port=3 ...