Google Code Jam 2014 Round 1 A:Problem B. Full Binary Tree
Problem
A tree is a connected graph with no cycles.
A rooted tree is a tree in which one special vertex is called the root. If there is an edge between X and Y in a rooted tree, we say that Y is a child of X if X is closer to the root than Y (in other words, the shortest path from the root to X is shorter than the shortest path from the root to Y).
A full binary tree is a rooted tree where every node has either exactly 2 children or 0 children.
You are given a tree G with N nodes (numbered from 1 to N). You are allowed to delete some of the nodes. When a node is deleted, the edges connected to the deleted node are also deleted. Your task is to delete as few nodes as possible so that the remaining nodes form a full binary tree for some choice of the root from the remaining nodes.
Input
The first line of the input gives the number of test cases, T. T test cases follow. The first line of each test case contains a single integer N, the number of nodes in the tree. The following N-1 lines each one will contain two space-separated integers: Xi Yi, indicating that G contains an undirected edge between Xi and Yi.
Output
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the minimum number of nodes to delete from G to make a full binary tree.
Limits
1 ≤ T ≤ 100. 1 ≤ Xi, Yi ≤ N Each test case will form a valid connected tree.
Small dataset
2 ≤ N ≤ 15.
Large dataset
2 ≤ N ≤ 1000.
Sample
| Input | Output |
3 |
Case #1: 0 |
In the first case, G is already a full binary tree (if we consider node 1 as the root), so we don't need to do anything.
In the second case, we may delete nodes 3 and 7; then 2 can be the root of a full binary tree.
In the third case, we may delete node 1; then 3 will become the root of a full binary tree (we could also have deleted node 4; then we could have made 2 the root).
Google Code Jam 2014 Round 1 A:Problem B. Full Binary Tree的更多相关文章
- Google Code Jam 2014 Round 1 A:Problem C. Proper Shuffle
Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...
- Google Code Jam 2014 Round 1 A:Problem A Charging Chaos
Problem Shota the farmer has a problem. He has just moved into his newly built farmhouse, but it tur ...
- Google Code Jam 2014 Round 1B Problem B
二进制数位DP,涉及到数字的按位与操作. 查看官方解题报告 #include <cstdio> #include <cstdlib> #include <cstring& ...
- [C++]Store Credit——Google Code Jam Qualification Round Africa 2010
Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...
- Google Code Jam 2010 Round 1C Problem A. Rope Intranet
Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...
- [Google Code Jam (Qualification Round 2014) ] B. Cookie Clicker Alpha
Problem B. Cookie Clicker Alpha Introduction Cookie Clicker is a Javascript game by Orteil, where ...
- [Google Code Jam (Qualification Round 2014) ] A. Magic Trick
Problem A. Magic Trick Small input6 points You have solved this input set. Note: To advance to the ...
- Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha
Introduction Cookie Clicker is a Javascript game by Orteil, where players click on a picture of a gi ...
- [C++]Saving the Universe——Google Code Jam Qualification Round 2008
Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...
随机推荐
- [POJ 1935] Journey
Link: POJ1935 传送门 Solution: 一道吓唬人的水题 注意这是一棵树,两点间仅有唯一的路径! 于是每个“关键点”和起点只有一条路径,想去起点另一棵子树上的节点必须要回到起点 如果必 ...
- linux-系统资源查看-动态
1.top 2.sar http://blog.csdn.net/hguisu/article/details/7493661 很重要 http://blog.itpub.net/24435147/ ...
- jQuery插件开发 总结
一般来说,jQuery插件的开发分为两种:一种是挂在jQuery命名空间下的全局函数,也可称为静态方法:另一种是jQuery对象级别的方法,即挂在jQuery原型下的方法,这样通过选择器获取的jQue ...
- linux的file指令
显示文件的类型,用命令 file 可以使你知道某个文件究竟是ELF格式的可执行文件, 还是shell script文 件或是其他的什么格式 例如:#file startx 语 法:file [-beL ...
- java拦截器与过滤器打印请求url与参数
HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpServle ...
- Ubuntu 16.04 -- 同时配置Nginx(转发)和frp(内网映射)和HTTPS(ca加密) - 端口转发
Ubuntu16.04下: sudo apt -get nginx 用这条命令安装完nginx之后, nginx在该目录下: 然后配置nginx: 如下: 红圈圈住的地方多写几个可以做负载均衡. 端口 ...
- 本地缓存localstorage使用
最近做项目遇到一个问题,即从“个人中心”点击进入“修改支付宝”,需要自动获取用户手机号怎么做? 修改支付宝的api不提供用户手机号数据,但是发现个人中心提供,于是想通过localstorage在个人中 ...
- centos7 安装LNMP(php7)之mysql安装,更改密码,远程授权
1.执行命令 yum install mysql mysql-server mysql-devel -y 知道出现complete!则安装mysql完成 当执行 service mysqld rest ...
- zabbix web监测
web monitoring(监测)属于业务监控,用来监控Web站点多方面的可用性,可以监控Web站点的下载速度.返回码和响应时间.Zabbix能够检测HTML中包含的预先定义的字符串,也可以模拟登录 ...
- Web项目中用mybatis配置多个数据库
需要在项目中配置多个数据库(比如一个mysql,一个oracle)的时候,可按照如下方式配置 首先是第一个数据库的配置 <bean name="transactionManager&q ...