HDU 6060 RXD and dividing
2017-08-01 21:26
537 查看
题目链接:
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 0x3f3f3f3f const 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); } }
相关文章推荐
- HDU 6060 RXD and dividing
- HDU 6060 RXD and dividing(树形DP+贪心)
- 2017 多校训练第三场 HDU 6060 RXD and dividing
- HDU 6060 RXD and dividing
- hdu 6060 RXD and dividing 2017多校第三场第五题(思维+dfs)
- HDU 6060 17多校3 RXD and dividing(树+dfs)
- HDU - 6060 RXD and dividing(树的dfs)
- HDU 6060 RXD and dividing (最小斯坦纳树)
- HDU 6060 RXD and dividing
- 17 多校 3 - 1005 - RXD and dividing (HDU 6060)
- 2017多校第3场 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(思维+计算贡献值)
- HDU 6060 RXD and dividing(思维)
- RXD and dividing(HDU 6060)
- HDU 6060 RXD and dividing(贪心,思维)
- HDU 6060 RXD and dividing【斯坦纳树】
- Hdu 6060 - RXD and dividing (dfs)