HDU 6060 RXD and dividing
来源:互联网 发布:类似于百度云的软件 编辑:程序博客网 时间:2024/06/05 14:33
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=6060
题解:
比赛的时候这道题目的方向想错了,到最后都没有过。。。。。。应该以边的方向去想,而不是以点的方向去想。(很绝望)
代码:
#include <map>#include <cmath>#include <cstdio>#include <vector>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define met(a,b) memset(a,b,sizeof(a))typedef long long ll;#define inf 0x3f3f3f3fconst int maxn = 1e6+10;vector<ll>p[maxn];map<ll,ll> mp[maxn];ll visited[maxn];ll n,k;ll ans;void dfs(ll x,ll f,ll w){ visited[x]=1; for(int i=0;i<p[x].size();i++) { ll y=p[x][i]; if(y==f) continue; dfs(y,x,mp[x][y]); visited[x]+=visited[y]; } ans+=w*min(k,visited[x]);}int main(){ while(scanf("%lld%lld",&n,&k)!=EOF) { for(int i=1;i<=n;i++) { p[i].clear(); mp[i].clear(); } for(int i=1;i<n;i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); p[a].push_back(b); p[b].push_back(a); mp[a][b]=c; mp[b][a]=c; } met(visited,0); ans=0; dfs(1,0,0); printf("%lld\n",ans); }}
阅读全文
0 0
- HDU 6060 RXD and dividing
- HDU 6060 RXD and dividing
- [HDU]-6060 RXD and dividing
- HDU 6060 RXD and dividing
- HDU-6060 RXD and dividing
- HDU 6060 RXD and dividing
- hdu 6060 RXD and dividing
- HDU 6060 RXD and dividing
- hdu--6060-RXD and dividing
- HDU 6060 RXD and dividing
- hdu-6060-RXD and dividing
- hdu--6060--RXD and dividing
- HDU 6060 RXD and dividing
- HDU 6060 RXD and dividing
- HDU 6060 RXD and dividing
- HDU 6060 RXD and dividing 思维 + dfs
- Hdu 6060 RXD and dividing【思维】
- HDU 6060 RXD and dividing [想法题]
- 前言:对XML文件的重新认识,说说XML文件的二三事(一)
- 线程创建
- 习题 2.4(6) 将100~200之间的素数输出。
- CodeForces 835A Key races
- js函数
- HDU 6060 RXD and dividing
- LinkdeList(链式集合)
- 整数的划分
- JAVA日期格式转换与数据类型转换
- for循环的闭包
- 彻底理解call()及其apply.bind
- 莫比乌斯反演
- ArrayList底层实现
- 《Mining Large Streams of User Data for Personalized Recommendations》笔记