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.42.0) (judge verdict: Time Limit Exceeded)

#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;
// 低速 EOF不要
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! mut_input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };mut_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()};mut_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! mut_input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let mut $var = read_value!($next, $t);mut_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")};}

fn main() {
    const U_INF: usize = 1 << 60;
    const I_INF: isize = 1 << 60;

    //ただの頂点の受け取り。O(2(n-1))
  	input!{
      	n: usize,
      	edges: [(usize1,usize1); n-1],
  	}
    // let n: usize = read!();
    let mut vertexes = vec![vec![]; n];
  	for i in 1..n{
      vertexes[edges[i-1].0].push(edges[i-1].1);
      vertexes[edges[i-1].1].push(edges[i-1].0);
  	}
    //頂点0に対して色が白黒2通りあるのでループ
    println!(
        "{}",
        (solve(0, U_INF, 0, &vertexes) + solve(0, U_INF, 1, &vertexes))%1000000007
    );
}

fn solve(now: usize, parent: usize, color: usize, vertexes: &Vec<Vec<usize>>) -> i64 {
    // let mut cnt = ModUsize::new(1);
	let mut cnt = 1_i64;

    //今の色に応じて白だけor白と黒両方見る
    let next_colors = if color == 1 { &[0][..] } else { &[0, 1][..] };
    //今の頂点とつながっている頂点のうち親でないもの全てに対して
    for &v in &vertexes[now] {
        if v == parent {
            continue;
        } else {
            // let mut tmp = ModUsize::new(0);
          	let mut tmp = 0_i64;  
          
          	//再帰
            for &c in next_colors {
                tmp += solve(v, now, c, vertexes);
              
              	tmp %= 1000000007;
            }
            cnt *= tmp;
          	cnt %= 1000000007;
        }
    }
    cnt
}