Let’s imagine how apple tree looks in binary computer world. You’re right, it looks just like a binary tree, i.e. any biparous branch splits up to exactly two new branches. We will enumerate by integers the root of binary apple tree, points of branching and the ends of twigs. This way we may distinguish different branches by their ending points. We will assume that root of tree always is numbered by 1 and all numbers used for enumerating are numbered in range from 1 to N, where N is the total number of all enumerated points. For instance in the picture below N is equal to 5. Here is an example of an enumerated tree with four branches:
2 5
\ /
3 4
\ /
1
As you may know it’s not convenient to pick an apples from a tree when there are too much of branches. That’s why some of them should be removed from a tree. But you are interested in removing branches in the way of minimal loss of apples. So your are given amounts of apples on a branches and amount of branches that should be preserved. Your task is to determine how many apples can remain on a tree after removing of excessive branches.
Input
First line of input contains two numbers: N and Q ( 2 ≤ N ≤ 100; 1 ≤ Q ≤ N − 1 ). N denotes the number of enumerated points in a tree. Q denotes amount of branches that should be preserved. Next N − 1 lines contains descriptions of branches. Each description consists of a three integer numbers divided by spaces. The first two of them define branch by it’s ending points. The third number defines the number of apples on this branch. You may assume that no branch contains more than 30000 apples.
Output
Output should contain the only number — amount of apples that can be preserved. And don’t forget to preserve tree’s root

Binary Apple Tree相关推荐

  1. (树形dp)Binary Apple Tree

    Let's imagine how apple tree looks in binary computer world. You're right, it looks just like a bina ...

  2. URAL1018 Binary Apple Tree

    非常经典的树形DP(假设不会树形DP建议先看下面..我就是先看了别的题,,握手的什么的) 给一棵树,留下N条边(它若留下边父亲的边比留下),,问最后苹果最多多少个....... 建树我认为非常费劲,, ...

  3. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

  4. 笔试算法题(58):二分查找树性能分析(Binary Search Tree Performance Analysis)

    议题:二分查找树性能分析(Binary Search Tree Performance Analysis) 分析: 二叉搜索树(Binary Search Tree,BST)是一颗典型的二叉树,同时任 ...

  5. 【ACM】二叉搜索树(Binary Search Tree /BS Tree) 小结

    动态管理集合的数据结构--二叉搜索树 搜索树是一种可以进行插入,搜索,删除等操作的数据结构,可以用字典或者优先队列. 二叉排序树又称为二叉查找树,他或者为空树,或者是满足如下性质的二叉树. (1)若它 ...

  6. 二叉搜索树(binary search tree)的建立、删除、查找

    由于输入的数据顺序不同,建立的bst会不一样.最坏的情况就是一个链,所以我们引入了平衡二叉树的概念.这里我们先来看binary search tree.(我随笔里面有一些相关知识) 建立(也就是插入) ...

  7. 查找二叉树中出现次数最多的数 Find Mode in Binary Search Tree

    为什么80%的码农都做不了架构师?>>>    问题: Given a binary search tree (BST) with duplicates, find all the  ...

  8. LeetCode 426. Convert Binary Search Tree to Sorted Doubly Linked List--转换二叉树为双向链表--Java,C++,Python解法

    题目地址:Convert Binary Search Tree to Sorted Doubly Linked List - LeetCode Convert a BST to a sorted ci ...

  9. LeetCode: 109. Convert Sorted List to Binary Search Tree

    题目 Given a singly linked list where elements are sorted in ascending order, convert it to a height b ...

最新文章

  1. “可扩展标记语言”(XML) 提供一种描述结构化数据的方法。
  2. 关于使用“JS获取屏幕,浏览器,网页高度宽度”的个人思考
  3. 【Linux运维】Centos7上借助ansible搭建LVS+Keepalived
  4. PHP不读取Excel空行,phpexcel中遇到空单元格不跳过
  5. Storm 1.0.1发布 .NET 适配也已到来
  6. 16.对极几何——介绍,立体视觉约束,条件_1
  7. 老年人学摄影,装备该如何选择?
  8. 添加css单词换行连字符
  9. 为什么天才容易患阅读障碍症_王俊凯因“耳石症”缺席跨年晚会,这种病与熬夜玩手机有关?...
  10. 计算机一级考试广告,2013年计算机一级考试MsOffice备考题及答案(21)
  11. Windows Redis 整理
  12. 基于Python自动登录QQ空间过滑块验证
  13. 【 开源计划 - Flutter组件 】 星星也可以如此闪耀 flutter_star
  14. linux mv文件个数,关于linux:mv一个文件,其中包含Shell脚本中的空格
  15. 三菱Q系列PLC ,QD77MS16走总线控制伺服项目
  16. 使用GoldenGate完成MySQL到MySQL的同步
  17. 新手入门matlab之线性系统频域分析
  18. Verilog HDL 硬件描述语言基础
  19. 关于汇编 BX 和 BLX 跳转指令
  20. H3C网络设备配置命令大全(持续更新)

热门文章

  1. 周志华《机器学习》课后习题解答系列(三):Ch2 - 模型评估与选择
  2. 双反斜杠无法访问其它计算机(0x80004005)
  3. 【又做了个视频......】到底什么是5G LAN?
  4. 机器人局部避障的动态窗口法DWA (dynamic window approach)-matlab代码修改及动态障碍物避障效果
  5. 细细品味ASP.NET (二)
  6. UniAPP社区项目实战教案
  7. Android开发之三种近场通信技术及未来近场通信技术前景
  8. R语言绘制IPCC风格箱线抖动点图
  9. 便宜的国外VPS主机带给你无与伦比的网站体验
  10. ArchLinux搭建tftpd服务器