Problem:
Score : 100 points

Problem Statement

There is a tree with N vertices, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i.

Taro has decided to paint each vertex in white or black.
Here, it is not allowed to paint two adjacent vertices both in black.

Find the number of ways in which the vertices can be painted, modulo 10^9 + 7.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq x_i, y_i \leq N

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1}

Output

Print the number of ways in which the vertices can be painted, modulo 10^9 + 7.

Sample Input 1

3
1 2
2 3

Sample Output 1

5

There are five ways to paint the vertices, as follows:

Sample Input 2

4
1 2
1 3
1 4

Sample Output 2

9

There are nine ways to paint the vertices, as follows:

Sample Input 3

1

Sample Output 3

2

Sample Input 4

10
8 5
10 8
6 5
1 5
4 8
2 10
3 6
9 2
1 7

Sample Output 4

157

Solution in Rust (1.15.1) (judge verdict: Accepted)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::{HashSet, VecDeque};

fn main() {
    input!{
        n: usize,
        v: [[usize1; 2]; n - 1]
    }
    if n == 1 {
        println!("2");
        return;
    }
    let d = 1000000007;
    let mut nodes: Vec<HashSet<usize>> = vec![HashSet::new(); n];
    for i in 0..n - 1 {
        nodes[v[i][0]].insert(v[i][1]);
        nodes[v[i][1]].insert(v[i][0]);
    }
    let mut tab: Vec<Vec<usize>> = vec![vec![1, 1]; n];
    let mut ch: Vec<Vec<usize>> = vec![Vec::new(); n];
    let mut ts: Vec<usize> = Vec::new();
    let mut s: VecDeque<usize> = VecDeque::new();
    for i in 0..n {
        if nodes[i].len() == 1 {
            s.push_back(i);
        }
    }

    loop {
        let x = s.pop_front().unwrap();
        ts.push(x);
        if nodes[x].len() == 0 {
            break;
        }
        let y = *nodes[x].iter().nth(0).unwrap();
        nodes[y].remove(&x);
        ch[y].push(x);
        if nodes[y].len() == 1 {
            s.push_back(y);
        }
    }
    for i in ts.iter().clone().map(|x| *x) {
        for j in ch[i].iter().clone().map(|x| *x) {
            tab[i][0] = tab[i][0] * (tab[j][0] + tab[j][1]) % d;
            tab[i][1] = tab[i][1] * tab[j][0] % d;
        }
    }
    let l = *ts.last().unwrap();
    println!("{}", (tab[l][0] + tab[l][1]) % d);
}