#include using namespace std; #define int long long const int p=998244353; int po(int a,int b) {if(b==0) return 1;if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*u)%p;} else {int u=po(a,b-1);return (a*u)%p;}} const int maxn=2e5+5; vector a[maxn];bool used[maxn];int corn[maxn];int cn=0; void dfs(int x,int pr) { used[x]=true; for(int v:a[x]) { if(!used[v]) { corn[v]=corn[x]+1; dfs(v,x); } else if(v!=pr && corn[v]>n>>k; for(int i=0;i>x>>y;--x;--y; a[x].push_back(y);a[y].push_back(x); } dfs(0,-1); int res=po(k-1,cn);if(cn%2==0) {res+=(k-1);} else {res-=(k-1);} res%=p; res*=po(k-1,n-cn);res%=p; cout<<(res%p+p)%p; return 0; }