#include <bits/stdc++.h>
#define int long long
using namespace std;
const int max_n=3e5+5,mod=998244353;
int n,ans,dp[max_n];
vector<int>tree[max_n];
void clear()
{
for(int i=1;i<=n;i++){
tree[i].clear();
dp[i]=0;
}
ans=0;
}
void dfs(int u,int fa)
{
dp[u]=1;
for(auto &ti:tree[u]){
if(ti^fa){
dfs(ti,u);
dp[u]=(dp[u]*(dp[ti]+1))%mod;
}
}
ans=(ans+dp[u])%mod;
}
void solve()
{
cin>>n;
for(int i=1;i<=n-1;i++){
int u,v;cin>>u>>v;
tree[u].push_back(v);
tree[v].push_back(u);
}
dfs(1,0);
cout<<(ans+1)%mod<<endl;
clear();
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int _t;cin>>_t;
while(_t--){
solve();
}
return 0;
}
D. Sasha and a Walk in the City
最新推荐文章于 2024-09-27 14:28:55 发布