CF1929D.Sasha and a Walk in the City

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Sasha wants to take a walk with his girlfriend in the city. The city consists of nn intersections, numbered from 11 to nn . Some of them are connected by roads, and from any intersection, there is exactly one simple path ^{\dagger} to any other intersection. In other words, the intersections and the roads between them form a tree.

Some of the intersections are considered dangerous. Since it is unsafe to walk alone in the city, Sasha does not want to visit three or more dangerous intersections during the walk.

Sasha calls a set of intersections good if the following condition is satisfied:

  • If in the city only the intersections contained in this set are dangerous, then any simple path in the city contains no more than two dangerous intersections.

However, Sasha does not know which intersections are dangerous, so he is interested in the number of different good sets of intersections in the city. Since this number can be very large, output it modulo 998244353998\,244\,353 .

^{\dagger} A simple path is a path that passes through each intersection at most once.

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn ( 2n31052 \le n \leq 3 \cdot 10^5 ) — the number of intersections in the city.

The next (n1)(n - 1) lines describe the roads. The ii -th line contains two integers uiu_i and viv_i ( 1ui,vin1 \leq u_i, v_i \leq n , uiviu_i \ne v_i ) — the numbers of the intersections connected by the ii -th road.

It is guaranteed that these roads form a tree.

It is guaranteed that the sum of nn over all test cases does not exceed 31053 \cdot 10^5 .

输出格式

For each test case, output a single integer — the number of good sets of intersections modulo 998244353998\,244\,353 .

输入输出样例

  • 输入#1

    4
    3
    1 3
    3 2
    4
    3 4
    2 3
    3 1
    5
    1 2
    3 4
    5 1
    2 3
    4
    1 2
    2 3
    3 4

    输出#1

    7
    12
    16
    11

说明/提示

In the first test case, there are 23=82^3 = 8 sets of intersections. All of them are good, except for the set {1,2,3}\{1, 2, 3\} , because if intersections 1,21, 2 , and 33 are dangerous, then the simple path 1231 - 2 - 3 contains 33 dangerous intersections. Thus, there are 77 good sets.

In the second test case, there are 24=162^4 = 16 sets of intersections. Among them, the sets {1,2,3,4}\{1, 2, 3, 4\} , {1,2,3}\{1, 2, 3\} , {1,3,4}\{1, 3, 4\} , {2,3,4}\{2, 3, 4\} are not good. Thus, there are a total of 1212 good sets. The city layout is shown below:

首页