package main import ( "bufio" "fmt" "os" "strconv" ) func getScanner(fp *os.File) *bufio.Scanner { scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) return scanner } func getNextString(scanner *bufio.Scanner) string { scanner.Scan() return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextUint64(scanner *bufio.Scanner) uint64 { i, _ := strconv.ParseUint(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout cnt := 0 if os.Getenv("MASPY") == "ますピ" { fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT")) cnt = 2 } if os.Getenv("MASPYPY") == "ますピッピ" { wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10")) } scanner := getScanner(fp) writer := bufio.NewWriter(wfp) solve(scanner, writer) for i := 0; i < cnt; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } writer.Flush() } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) ee := make([][]edge, n) for i := 0; i < n-1; i++ { a := getNextInt(scanner) - 1 b := getNextInt(scanner) - 1 appendEdge(a, b, i, ee) appendEdge(b, a, i, ee) } fmt.Fprintln(writer, dfs(0, -1, ee)) } func dfs(c, p int, ee [][]edge) int { cnt := len(ee[c]) - 2 if len(ee[c]) == 1 { if p != -1 { return 0 } cnt = 0 } for _, e := range ee[c] { if e.to == p { continue } cnt += dfs(e.to, c, ee) } return cnt } func appendEdge(from, to, id int, ee [][]edge) { ee[from] = append(ee[from], edge{ to: to, id: id, }) } type edge struct { to, id int }