#include using namespace std; long long mod = 998244353; //入力が必ず-mod>= 1; } return ret; }; mint &operator=(const mint &b) = default; mint operator-() const {return mint(0)-(*this);} mint operator+(const mint b){return mint(v)+=b;} mint operator-(const mint b){return mint(v)-=b;} mint operator*(const mint b){return mint(v)*=b;} mint operator/(const mint b){return mint(v)/=b;} mint operator+=(const mint b){ v += b.v; if(v >= mod) v -= mod; return *this; } mint operator-=(const mint b){ v -= b.v; if(v < 0) v += mod; return *this; } mint operator*=(const mint b){v = v*b.v%mod; return *this;} mint operator/=(mint b){ if(b == 0) assert(false); int left = mod-2; while(left){if(left&1) *this *= b; b *= b; left >>= 1;} return *this; } mint operator++(int){*this += 1; return *this;} mint operator--(int){*this -= 1; return *this;} bool operator==(const mint b){return v == b.v;} bool operator!=(const mint b){return v != b.v;} bool operator>(const mint b){return v > b.v;} bool operator>=(const mint b){return v >= b.v;} bool operator<(const mint b){return v < b.v;} bool operator<=(const mint b){return v <= b.v;} mint pow(const long long x){return repeat2mint(v,x);} mint inv(){return mint(1)/v;} }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector A(N); for(auto &a : A) cin >> a.v; vector> Graph(N); for(int i=0; i> u >> v; u--; v--; Graph.at(u).push_back(v); Graph.at(v).push_back(u); } vector stop(N); auto findsiz = [&](auto&& self,int pos,int back) -> int { if(stop.at(pos)) return 0; int ret = 1; for(auto to : Graph.at(pos)) if(to != back) ret += self(self,to,pos); return ret; }; auto findcent = [&](int start) -> int { int siz = findsiz(findsiz,start,-1); int cent = -1; auto dfs = [&](auto dfs,int pos,int back) -> int { if(stop.at(pos)) return 0; int ret = 0; bool iscent = true; for(auto to : Graph.at(pos)) if(to != back){ int ko = dfs(dfs,to,pos); if(ko > siz/2) iscent = false; ret += ko; } ret++; if(siz-ret > siz/2) iscent = false; if(iscent) cent = pos; return ret; }; dfs(dfs,start,-1); return cent; }; mint answer = 0; queue Q; Q.push(0); mint div2 = mint(1)/2; while(Q.size()){ int start = Q.front(); Q.pop(); int cent = findcent(start); int n = Graph.at(cent).size(); vector sum(n); auto dfs = [&](auto dfs,int pos,int back,mint now,int i) -> void { if(stop.at(pos)) return; now *= A.at(pos); sum.at(i) += now; for(auto to : Graph.at(pos)) if(to != back) dfs(dfs,to,pos,now,i); }; for(int i=0; i