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, TT 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 #xy", 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 ≤ XiYi ≤ N Each test case will form a valid connected tree.

Small dataset

2 ≤ N ≤ 15.

Large dataset

2 ≤ N ≤ 1000.

Sample

Input    Output   
3
3
2 1
1 3
7
4 5
4 2
1 2
3 1
6 4
3 7
4
1 2
2 3
3 4
Case #1: 0
Case #2: 2
Case #3: 1

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Google Code Jam 2014 Round 1B Problem B

    二进制数位DP,涉及到数字的按位与操作. 查看官方解题报告 #include <cstdio> #include <cstdlib> #include <cstring& ...

  4. [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 ...

  5. 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 ...

  6. [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 ...

  7. [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 ...

  8. 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 ...

  9. [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 ...

随机推荐

  1. HDU 3237 Tree(树链剖分)(线段树区间取反,最大值)

    Tree Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 9123   Accepted: 2411 Description ...

  2. 洛谷 P3636 曲面

    题目背景 xht喜欢研究数学函数,他特别喜欢反比例函数. 题目描述 我们知道,反比例函数xy=a的图象是双曲线. xht于是想:把它推广到三维是什么样的呢? 定义曲面C(k)为方程xyz=k所确定的曲 ...

  3. 初学Django:创建第一个项目+使用模板

    1. 创建一个项目 之前在Anaconda 3里面用命令行安装了Django之后,有了可用的管理工具django-admin.py (1)用django.admin.py来创建一个项目Hellowor ...

  4. IOS调用WCF提供的服务方法,但是方法的参数是WCF那边自定义的对象,这样有办法调用么,如果可以IOS应该怎么传参呢?请问有了解的么,

    最近做一个项目后端使用WCF接收Android手机拍照并带其它参数保存到服务器里:刚好把最近学习的WCF利用上,本以为是个比较简单的功能应该很好实现,没想到其中碰到不少问题,在网上搜索很久一直没有想到 ...

  5. IOS提示控件UIActionSheet,UIAlertView

    iphone中常用的消息提示控件,就是UIActionSheet和UIAlertView了,在Web开发中,UIActionSheet就像是confirm(),而UIAlertView就像是alert ...

  6. iis7文件夹 首页设置

    iis7在默认文档中可以设置首页,一般可以直接设置网站根目录下的页面为首页,但是当页面不在根目录下时,直接按路径添加就不行了,如“admin/default.aspx”.添加完后只有“default. ...

  7. linux 下查看硬件信息(mac,IP地址,硬盘型号,序列号等)

    一.查看网卡mac地址 #安装lshw [root@server ~]# yum install lshw #使用方法 [root@rsync-server ~]# lshw -c network * ...

  8. Linux下自动监测并重启Apache服务脚本

    为了达到一个高可用的基于Apache的网站环境,在Apache由于种种原因自动停止运行之后,想立即恢复网站访问,这就需要有个工具实时监测Apache的运行状态并能够自动重启httpd服务,写了一个简单 ...

  9. PS如何精确设置参考线,标尺,辅助线

    如图所示,我要均分画布的垂直方向为三份.因为要图标的三个位置文件吻合的很精确.我们先拉好头尾两条辅助线 在标尺上右击可以切换显示的单位,但是还是不够精确.因为这个画布是64×192的.我要64×64给 ...

  10. 【C#】.NET提供了哪些类型来实现反射

    实现反射的类型大多数都定义在System.Reflection命名空间之下. Assembly 定义一个Assembly,它是可重用.无版本冲突并且可自我描述的公共语言运行库应用程序构造块. Asse ...