bzoj1296
来源:互联网 发布:大数据时代pdf百度云 编辑:程序博客网 时间:2024/06/05 12:41
啊啊啊啊啊,满脑子CO2,
竟然链式前向星数组没开两倍,调了10min RE
我太菜了
还是少喝碳酸饮料
#include<bits/stdc++.h>using namespace std;#define FOR(i,s,t) for(int i=(s);i<=(t);i++)inline int read(void){ int x = 0, c, f = 1; do{c=getchar();if(c=='-')f=-1;}while(c<'0'||c>'9'); do{x=x*10+c-'0';c=getchar();}while(c>='0'&&c<='9'); return x * f;}typedef long long LL;#define INF LONG_LONG_MAXconst int N = 110000;int a[N] ,n, to[2*N], fir[N], dis[2*N], nxt[2*N], Index, fa[N];LL C[N], fad[N];LL f[N], pre[N], pt[N], ans = INF, d;inline void addedge(int u,int v,int s){ to[++Index] = v, dis[Index] = s, nxt[Index] = fir[u], fir[u] = Index;}void dfs(int x, int Fa) { C[x] = a[x]; for (int i = fir[x]; i; i = nxt[i]) if(to[i] != fa[x]){ if (to[i] == Fa)continue; fa[to[i]] = x, fad[to[i]] = dis[i]; dfs(to[i], x); C[x] += C[to[i]]; f[x] += C[to[i]] * dis[i] + f[to[i]]; }}void DP(int x, int Fa){ pre[x] = fa[x] == 0 ? 0 : pre[fa[x]] + C[fa[x]] - C[x]; pt[x] = fa[x] == 0 ? 0 : pt[fa[x]] + f[fa[x]] - C[x] * fad[x] - f[x] + pre[x] * fad[x]; ans = min(ans, pt[x] + f[x]); for (int i = fir[x]; i; i = nxt[i]) if(to[i] != fa[x]) { if (to[i] == Fa)continue; DP(to[i], x); }}int main(){ n = read(); for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1, u ,v, s; i < n; i++) { u = read(), v = read(), s = read(); addedge(u,v,s), addedge(v,u,s); } dfs(1,0), DP(1,0); printf("%lld\n",ans);}
0 0
- bzoj1296
- bzoj1296
- BZOJ1296【动态规划】
- [BZOJ1296][SCOI2009]粉刷匠
- bzoj1296【SCOI2009】粉刷匠
- BZOJ1296: [SCOI2009]粉刷匠
- BZOJ1296: [SCOI2009]粉刷匠
- bzoj1296 [SCOI2009]粉刷匠
- bzoj1296: [SCOI2009]粉刷匠
- BZOJ1296: [SCOI2009]粉刷匠
- 【bzoj1296】[SCOI2009]粉刷匠
- BZOJ1296: [SCOI2009]粉刷匠 DP
- bzoj1296: [SCOI2009]粉刷匠 DP
- 【bzoj1296】【scoi2009】【粉刷匠】【dp】
- bzoj1296(dp套背包dp)
- 动态规划 BZOJ1296 [SCOI2009]粉刷匠
- bzoj1296 [SCOI2009]粉刷匠(dp+分组背包)
- bzoj1296 [SCOI2009]粉刷匠 ( 分组背包DP )
- Money
- 近期个人总结~
- 本人菜鸟 零基础学习MVC
- jquery的size()方法不能用
- mybaits中的批量操作
- bzoj1296
- 阿里物联网套件-服务端SDK学习实践(开篇)
- Web10. CSS浮动与定位
- 免费的论文查重网站
- js实现扇形旋转导航制作
- JVM调优
- 【其他】macos安装git及上传文件到github
- redis的数据类型-set
- compoundbutton调用setChecked触发onCheckedChanged的终极解决方案;