No.3412 Christmas Tree Coloring
タグ : / 解いたユーザー数 60
作問者 :
AwashAmityOak
kazuppa
Story
kazuppa, AwashAmityOak, Yu~, and Ruku are getting ready for a Christmas party.
Yu~ is in charge of decorating the Christmas tree. She will decorate the Oak tree that AwashAmityOak bought.
Yu~: "Aren't Christmas trees supposed to be fir trees?"
The work has begun, but Yu~ has started to wonder how many possible decoration patterns there are.
Problem Statement
You are given a tree with $N$ vertices. The vertices and the edges are each numbered $1,2,\dots$ in order, and edge $i$ connects vertices $a_i$ and $b_i$.
What is a tree?
A tree is a connected undirected graph (one in which every vertex can be reached from every other vertex by traversing edges) with $x$ vertices and $x-1$ edges.
Consider painting each vertex of this tree either red, green, or brown. A painted tree is called a Christmas tree if it satisfies the following conditions.
- For each of red, green, and brown, there exist $1$ or more vertices painted that color.
- There is exactly $1$ vertex painted brown.
- No two vertices painted the same color are directly connected by an edge.
How many possible Christmas trees are there?
Since the answer can be very large, output the answer modulo $998244353$.
Here, $2$ Christmas trees are considered different if there is a vertex painted a different color.
Input
$N$
$a_1\ b_1$
$a_2\ b_2$
$\cdots$
$a_{N-1}\ b_{N-1}$
Constraints
- $3 \le N \le 2\times 10^5$
- $1\le a_i < b_i \le N$
- The given graph is a tree.
Output
Print a newline at the end.
Sample
Sample 1
Input
5 1 2 1 3 3 4 1 5
Output
18
For example, the tree painted as shown below is a Christmas tree. (Many other Christmas trees are possible as well.)
Sample 2
Input
10 6 9 1 8 2 7 1 3 2 4 5 10 3 5 1 6 1 2
Output
46
No sample requires this operation because the input size would become too large, but note that you must output the answer modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。