【图论】[NOIP2014]联合权值
来源:互联网 发布:淘宝怎么设置地区不卖 编辑:程序博客网 时间:2024/05/18 00:52
题目
做完之后感觉 这个题应该是需要一些数学思想
题解看这个博客:链接
代码如下
#include<iostream>#include<cstdio>#include<cctype> using namespace std; #define in = read(); typedef long long ll; typedef unsigned int ui; const ll size = 1000000 + 10000; struct point{ ll next,to,dis;}edge[size]; ui n; ui a[size]; ui site,ans,maxans; ui head[size];inline ll read(){ ll num = 0 , f = 1; char ch = getchar(); while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)){ num = num*10 + ch - '0'; ch = getchar(); } return num*f;}inline void add(ll x,ll y){ edge[++site].next = head[x]; edge[site].to = y; head[x] = site;}int main(){ n in; for(int i=1;i<n;i++){ ui x,y; x in; y in; add(x,y); add(y,x); } for(int i=1;i<=n;i++){ a[i] in; a[i] %= 10007; } for(register int i=1;i<=n;i++){ ll sum = 0; ui max1= 0 , max2 = 0; for(register int j=head[i];j;j=edge[j].next){ if(a[edge[j].to] > max1){ max2 = max1; max1 = a[edge[j].to]; } else if(a[edge[j].to] > max2) max2 = a[edge[j].to]; ans = (ans + sum*a[edge[j].to])%10007; sum = (sum + a[edge[j].to])%10007; maxans = max(maxans , max1*max2); } } ans = (ans*2)%10007; printf("%d %d",maxans,ans);}//COYG
阅读全文
0 0
- 【图论】[NOIP2014]联合权值
- NOIP2014 联合权值
- NOIP2014联合权值
- NOIP2014联合权值
- 【noip2014】联合权值
- NOIP2014 联合权值
- 【NOIP2014】 联合权值
- noip2014联合权值
- NOIP2014 联合权值
- 【NOIP2014】联合权值
- 【NOIP2014 联合权值】
- [NOIP2014]联合权值
- NOIP2014联合权值
- [noip2014]联合权值
- 【NOIP2014提高】联合权值
- 【乱搞】noip2014联合权值
- 【NOIP2014】联合权值 乱搞
- 【NOIP2014】Day1T2 联合权值
- 笨方法学python 习题27(逻辑之前的内容)习题28(布尔)29、30、31
- Ubuntu16 编译源码出错 unsupported reloc 43
- Hadoop 学习链接
- CCF——出现最多的数
- 关于hive查询与MapReduce并行计算
- 【图论】[NOIP2014]联合权值
- 判断100-200之间有多少素数 并输出所有素数
- oracle位图索引
- Spring AOP之aop:config
- 微信公众平台开发的价值-微信开发教程1
- Linux服务器部署
- gcc -I参数和-L参数
- Listener
- recipe commences before first target. Stop 错误分析