Tree coloring 2 - MarisaOJ: Marisa Online Judge

Tree coloring 2

Time limit: 1000 ms
Memory limit: 256 MB
Given a tree of $n$ vertices. Count the number of way to color vertices in 3 colors so that no 2 adjacent vertices having the same color. ### Input - The first line contains an integer $n$. - The next $n - 1$ lines, each line contains 2 integers $u, v$, there is an edge between $u$ and $v$. ### Output - Print the number ways to color the tree, modulo $10^9+7$. ### Constraints - $1 \le n \le 10^5$. - $1 \le u, v \le n$. ### Example Input: ``` 5 1 2 1 3 2 4 2 5 ``` Output: ``` 48 ```