import java.util.HashSet; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { private static HashSet<Integer>[] adj; public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ solution(in); } } /** * 模拟法: bfs * 只有最长路径才不会重复走两次 -> 2*总边数-最长路径边数 * @param in */ private static void solution(Scanner in){ int V = in.nextInt(); int E = V-1; // 构建图 点的范围[1:V] adj = new HashSet[V+1]; for(int i=1; i<=V; i++){ adj[i] = new HashSet<>(); } int v1,v2; for(int i=1; i<=E; i++){ v1 = in.nextInt(); v2 = in.nextInt(); adj[v1].add(v2); adj[v2].add(v1); } // 最长路径边数 int edges = bfs(1); System.out.println(2*E-edges); } /** * 广度优先搜索 * @param start * @return 返回最长路径边数 */ private static int bfs(int start){ HashSet<Integer> visited = new HashSet<>(); Queue<Integer> queue = new LinkedList<>(); visited.add(start); queue.offer(start); int depth = 0; int size; while(!queue.isEmpty()){ Integer u; depth++; size = queue.size(); for(int i=1; i<=size; i++){ u = queue.poll(); for(Integer v: adj[u]){ if(!visited.contains(v)){ visited.add(v); queue.offer(v); } } } } return depth-1; } }