题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4714
/*
一般一个点的度如果大于2的话,该点必然要断开一些连接,
因为最终每个点的度都是2, 然后就是看点上断开那些连接了,
其实,如果一个节点的除去父亲节点如果度大于1,例如为5的话,
必然断开与父亲节点的那条边,且断掉其子节点的中的三条边,共删去4条边
*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x7fffffff
#define Max 1000000
vector<int>tree[Max+10];
int vis[Max+10];
int N,ans;
int DFS(int node){
vis[node] = 1;
int child_node = 0;
for(int i = 0; i < tree[node].size(); i++){
int temp = tree[node][i];
if(!vis[temp]){
child_node += DFS(temp);
}
}
if(child_node >= 2){
if(node == 1)
ans += child_node-2; //如果是根节点,
else
ans += child_node-1; //有两个以上节点,必然需要减去childe_node-1个边
return 0; //与父节点的边已经断了,不再是子节点
}
return 1;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
for(int i = 0 ; i <= N; i ++)
tree[i].clear();
memset(vis,0,sizeof(vis));
ans = 0;
N--;
while(N--){
int a,b;
scanf("%d%d",&a,&b);
tree[a].push_back(b);
tree[b].push_back(a);
}
DFS(1);
printf("%d\n",ans*2+1);
}
return 0;
}