問題一覧 > 通常問題

No.3412 Christmas Tree Coloring

レベル : / AI推定難易度 : 1050 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 60
作問者 : yuusaan / テスター : AwashAmityOak kazuppa ルク
お気に入りにしたユーザー ProblemId : 12867 / 自分の提出
問題文最終更新日: 2025-12-19 06:07:41
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2025 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。