TJU-3980Painting Tree(贪心)
2015-07-12 13:23
519 查看
贪心:有多少叶子节点,就有多少条路径。每个父亲节点与各个儿子节点相连的路径中,只有最小的那个会被选中。
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; const long long MAXM=0X3F3F3F3F; const int N=10000; long long l[N+5]; long long min(long long x,long long y) { return x<y?x:y; } void work(int n) { int i,j,f,cnt; long long len,ans; for(i=0;i<=n;i++) l[i]=MAXM; for(i=1;i<n;i++) { scanf("%d%lld",&f,&len); l[f]=min(l[f],len); } ans=0; cnt=0; for(i=0;i<n;i++) { if(l[i]!=MAXM) ans+=l[i]; else cnt++; } printf("%d %lld\n",cnt,ans); } int main() { int T,n; T=0; while(~scanf("%d",&n)) { printf("Case #%d: ",++T); work(n); } return 0; }
相关文章推荐
- 酷融贷kurongdai来啦
- 微软官方Windows主题 英国之美2 Great Britain 高分辨率的壁纸
- 微软官方Windows主题 英国之美2 Great Britain 高分辨率的壁纸
- WIP jobs available to MRP
- macbook air 开机黑屏解决方法
- 安装rails遇到的问题
- LintCode Climbing Stairs 爬楼梯
- 【概率】Uva 10900 - So you want to be a 2n-aire?
- EF--Validation failed for one or more entities. See ‘EntityValidationErrors’解决方法
- Svnmailer部署及应用
- AIX系统维护手册二.双机配置,HACMP
- AIX系统维护手册一.系统盘镜像
- my email is nuoyaxingzhe@sina.com
- @(报错)could not find the main class, Program will exit(已解决)
- 2965 - Jurassic Remains
- AIX查看某个端口被哪个进程占用并处理
- LeetCode题解——Container With Most Water
- Sicily 1509. Rails
- CLOSE_WAIT状态的原因与解决方法
- Altair.HWDesktop.v13.0.112.HotFix.Win64.&.Linux64 2CD有限元分析