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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <queue>
#define mod 1000000007

using namespace std;
int n,i,x,y;
struct nodS
{
    int parent=0,cop=0;
    bool viz=false;
    long long dpa=0, dpb=0;
    vector <int> vecini;
} nod[100005];
struct poz
{
    int parent, id;
    poz(int id, int parent)
    {
        this->id=id;
        this->parent=parent;
    }
};
queue <poz> q;
queue <int> q2;
int main()
{
    cin>>n;
    for(i=1;i<n;i++)
    {
        cin>>x>>y;
        nod[x].vecini.push_back(y);
        nod[y].vecini.push_back(x);
    }
    for(auto it : nod[1].vecini)
    {
        nod[1].cop++;
        q.push(poz(it, 1));
    }


    while(!q.empty())
    {
        poz curr=q.front();
        nod[curr.id].parent=curr.parent;
        for(auto it : nod[curr.id].vecini)
            if(it!=curr.parent)
            {
                q.push(poz(it, curr.id));
                nod[curr.id].cop++;
            }

        q.pop();
    }

    for(i=1;i<=n;i++)
    {
        cout<<nod[i].parent<<' '<<nod[i].cop<<'\n';
    }

    for(i=1;i<=n;i++)
    {
        if(!nod[i].cop)
            q2.push(i);
    }
    while(!q2.empty())
    {
        int now=q2.front();
        if(!nod[now].viz)
        {
            nod[now].viz=true;
            if(!nod[now].cop)
            {
                nod[now].dpa=1;
                nod[now].dpb=1;
            }
            nod[nod[now].parent].dpa+=nod[now].dpa+nod[now].dpb;
            nod[nod[now].parent].dpa%=mod;
            nod[nod[now].parent].dpb+=nod[now].dpa;
            nod[nod[now].parent].dpb%=mod;
            q2.push(nod[now].parent);
        }
        q2.pop();
    }

    /*
    for(i=1;i<=n;i++)
    {
        cout<<nod[i].dpa<<' '<<nod[i].dpb<<'\n';
    }
    */

    cout<<(nod[1].dpa+nod[1].dpb)%mod;
    return 0;
}