Language: C++

pub trait Graph<'a> {
    type Edge: 'a;
    type DIter: Iterator<Item = &'a (usize, Self::Edge)>;
    fn vertices(&self) -> usize;
    fn delta(&'a self, v: &usize) -> Self::DIter;
}

pub struct DirectedGraph<E> {
    g: Vec<Vec<(usize, E)>>
}

impl<'a, E: 'a> Graph<'a> for DirectedGraph<E> {
    type Edge = E;
    type DIter = std::slice::Iter<'a, (usize, E)>;
    fn vertices(&self) -> usize {
        self.g.len()
    }
    fn delta(&'a self, v: &usize) -> Self::DIter {
        self.g[*v].iter()
    }
}

impl<E> DirectedGraph<E> {
    pub fn new(n: usize) -> Self {
        DirectedGraph { g: (0..n).map(|_| Vec::new()).collect() }
    }
    pub fn from_iter(n: usize, iter: impl IntoIterator<Item = (usize, usize, E)>) -> Self {
        let mut g = Self::new(n);
        for (f, t, e) in iter {
            g.add_edge(f, t, e);
        }
        g
    }
    pub fn add_edge(&mut self, from: usize, to: usize, e: E) {
        self.g[from].push((to, e));
    }

    pub fn dfs(&self, v: &usize, p: &usize) -> u64 {
        let mut ans = 0u64;
        let mut zeros = 0u64;
        for (t, _) in self.delta(&v) {
            if t == p { continue }
            let res = self.dfs(t, v);
            ans += res;
            if res == 0 { zeros += 1 }
        }
        if zeros > 1 { ans += zeros - 1 }
        ans
    }
}

fn main() {
    ioset! { inp, buf }
    macro_rules! scan {
        ($($r:tt)*) => {
            input! { inp, $($r)* }
        }
    }
    macro_rules! print {
        ($($t:expr),*) => {
            write!(buf, $($t),*).unwrap();
        } 
    }

    scan! {
        n: usize,
        es: [(usize, usize); n - 1],
    }
    let mut deg = vec![0; n];
    let mut g = DirectedGraph::new(n);
    for &(a, b) in es.iter() {
        g.add_edge(a, b, ());
        g.add_edge(b, a, ());
        deg[a] += 1;
        deg[b] += 1;
    }
    let root = (0..n).max_by_key(|&v| deg[v]).unwrap();
    let ans = if deg[root] <= 2 {
        1
    }
    else {
        g.dfs(&root, &n)
    };
    print!("{}\n", ans);
}


use std::io::{ stdout, BufWriter, Write };

#[macro_export]
macro_rules! ioset {
    ($inp:ident, $buf:ident) => {
        inset!($inp);
        outset!($buf);
    }
}

#[macro_export]
macro_rules! inset {
    (source = $s:expr, $iter:ident) => {
        let mut $iter = $s.split_whitespace();
    };
    ($iter:ident) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut $iter = s.split_whitespace();
    }
}

#[macro_export]
macro_rules! input {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt, $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input! { $iter, $($r)* }
    };
    ($iter:expr, mut $var:ident : $t:tt, $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input! { $iter, $($r)* }
    };
    ($iter:expr, ($var:expr) : $t:tt, $($r:tt)*) => {
        $var = read_value!($iter, $t);
        input! { $iter, $($r)* }
    };
}

#[macro_export]
macro_rules! read_value {

    // tuple
    ($iter:expr, ( $($t:tt), * )) => {
        ( $(read_value!($iter, $t)), * )
    };
    
    // array
    ($iter:expr, [ $t:tt; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    
    // string
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    
    // any other
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[macro_export]
macro_rules! outset {
    ($buf:ident) => {
        let sout = stdout();
        let mut $buf = BufWriter::new(sout.lock());
    }
}

#[macro_export]
macro_rules! output {
    ($buf:expr, $($t:expr),*) => {
        write!($buf, $($t),*).unwrap();
    }
}

struct Chars<'a>(&'a Vec<char>);

impl<'a> std::fmt::Display for Chars<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
        write!(f, "{}", self.0.iter().collect::<String>())
    }
}


Compiler output:
a.cc:1:17: warning: missing terminating ' character
    1 | pub trait Graph<'a> {
      |                 ^
a.cc:1:17: error: missing terminating ' character
    1 | pub trait Graph<'a> {
      |                 ^~~~~
a.cc:2:16: warning: missing terminating ' character
    2 |     type Edge: 'a;
      |                ^
a.cc:2:16: error: missing terminating ' character
    2 |     type Edge: 'a;
      |                ^~~
a.cc:3:34: warning: missing terminating ' character
    3 |     type DIter: Iterator<Item = &'a (usize, Self::Edge)>;
      |                                  ^
a.cc:3:34: error: missing terminating ' character
    3 |     type DIter: Iterator<Item = &'a (usize, Self::Edge)>;
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:5:15: warning: missing terminating ' character
    5 |     fn delta(&'a self, v: &usize) -> Self::DIter;
      |               ^
a.cc:5:15: error: missing terminating ' character
    5 |     fn delta(&'a self, v: &usize) -> Self::DIter;
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:12:6: warning: multi-character literal with 6 characters exceeds 'int' size of 4 bytes
   12 | impl<'a, E: 'a> Graph<'a> for DirectedGraph<E> {
      |      ^~~~~~~~~
a.cc:12:23: warning: missing terminating ' character
   12 | impl<'a, E: 'a> Graph<'a> for DirectedGraph<E> {
      |                       ^
a.cc:12:23: error: missing terminating ' character
   12 | impl<'a, E: 'a> Graph<'a> for DirectedGraph<E> {
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:14:35: warning: missing terminating ' character
   14 |     type DIter = std::slice::Iter<'a, (usize, E)>;
      |                                   ^
a.cc:14:35: error: missing terminating ' character
   14 |     type DIter = std::slice::Iter<'a, (usize, E)>;
      |                                   ^~~~~~~~~~~~~~~~
a.cc:18:15: warning: missing terminating ' character
   18 |     fn delta(&'a self, v: &usize) -> Self::DIter {
      |               ^
a.cc:18:15: error: missing terminating ' character
   18 |     fn delta(&'a self, v: &usize) -> Self::DIter {
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:25:29: error: too many decimal points in number
   25 |         DirectedGraph { g: (0..n).map(|_| Vec::new()).collect() }
      |                             ^~~~
a.cc:77:17: error: too many decimal points in number
   77 |     let root = (0..n).max_by_key(|&v| deg[v]).unwrap();
      |                 ^~~~
a.cc:90:2: error: invalid preprocessing directive #[
   90 | #[macro_export]
      |  ^
a.cc:98:2: error: invalid preprocessing directive #[
   98 | #[macro_export]
      |  ^
a.cc:114:2: error: invalid preprocessing directive #[
  114 | #[macro_export]
      |  ^
a.cc:132:2: error: invalid preprocessing directive #[
  132 | #[macro_export]
      |  ^
a.cc:142:10: error: too many decimal points in number
  142 |         (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
      |          ^~~~~~~
a.cc:156:2: error: invalid preprocessing directive #[
  156 | #[macro_export]
      |  ^
a.cc:164:2: error: invalid preprocessing directive #[
  164 | #[macro_export]
      |  ^
a.cc:171:14: warning: multi-character character constant [-Wmultichar]
  171 | struct Chars<'a>(&'a Vec<char>);
      |              ^~~~~~~
a.cc:173:6: warning: multi-character literal with 31 characters exceeds 'int' size of 4 bytes
  173 | impl<'a> std::fmt::Display for Chars<'a> {
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:175:29: error: too many decimal points in number
  175 |         write!(f, "{}", self.0.iter().collect::<String>())
      |                             ^~~~~~~
a.cc:1:1: error: 'pub' does not name a type
    1 | pub trait Graph<'a> {
      | ^~~
a.cc:5:5: error: 'fn' does not name a type
    5 |     fn delta(&'a self, v: &usize) -> Self::DIter;
      |     ^~
a.cc:6:1: error: expected declaration before '}' token
    6 | }
      | ^
a.cc:8:1: error: 'pub' does not name a type
    8 | pub struct DirectedGraph<E> {
      | ^~~
a.cc:12:1: error: 'impl' does not name a type
   12 | impl<'a, E: 'a> Graph<'a> for DirectedGraph<E> {
      | ^~~~
a.cc:14:5: error: 'type' does not name a type; did you mean 'typeof'?
   14 |     type DIter = std::slice::Iter<'a, (usize, E)>;
      |     ^~~~
      |     typeof
a.cc:18:5: error: 'fn' does not name a type
   18 |     fn delta(&'a self, v: &usize) -> Self::DIter {
      |     ^~
a.cc:20:5: error: expected declaration before '}' token
   20 |     }
      |     ^
a.cc:21:1: error: expected declaration before '}' token
   21 | }
      | ^
a.cc:23:1: error: 'impl' does not name a type
   23 | impl<E> DirectedGraph<E> {
      | ^~~~
a.cc:52:1: error: 'fn' does not name a type
   52 | fn main() {
      | ^~
a.cc:88:1: error: 'use' does not name a type
   88 | use std::io::{ stdout, BufWriter, Write };
      | ^~~
a.cc:91:1: error: 'macro_rules' does not name a type
   91 | macro_rules! ioset {
      | ^~~~~~~~~~~
a.cc:99:1: error: 'macro_rules' does not name a type
   99 | macro_rules! inset {
      | ^~~~~~~~~~~
a.cc:115:1: error: 'macro_rules' does not name a type
  115 | macro_rules! input {
      | ^~~~~~~~~~~
a.cc:133:1: error: 'macro_rules' does not name a type
  133 | macro_rules! read_value {
      | ^~~~~~~~~~~
a.cc:157:1: error: 'macro_rules' does not name a type
  157 | macro_rules! outset {
      | ^~~~~~~~~~~
a.cc:165:1: error: 'macro_rules' does not name a type
  165 | macro_rules! output {
      | ^~~~~~~~~~~
a.cc:171:8: error: 'Chars' is not a class template
  171 | struct Chars<'a>(&'a Vec<char>);
      |        ^~~~~
a.cc:171:14: error: unable to find character literal operator 'operator""a' with 'int' argument
  171 | struct Chars<'a>(&'a Vec<char>);
      |              ^~~~~~~
a.cc:171:31: error: expected unqualified-id before ')' token
  171 | struct Chars<'a>(&'a Vec<char>);
      |                               ^
a.cc:173:1: error: 'impl' does not name a type
  173 | impl<'a> std::fmt::Display for Chars<'a> {
      | ^~~~