#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include #include using namespace std; using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/ #define pb push_back #define pf push_front #define fi first #define se second #define eb emplace_back #define endl '\n' #define SZ(x) ((ll)(x).size()) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define debug(v) cout<<#v<<":";for(auto x:v){cout< Point; // Point typedef long long ll; typedef vector vl; typedef vectorvvl; typedef vectorvvvl; typedef vectorvvvvl; typedef vectorvvvvvl; typedef pair P; typedef tuple T; template using minpq=priority_queue,greater>; const ll MOD=1000000007LL; // const ll MOD=998244353LL; const ll mod=MOD; string abc="abcdefghijklmnopqrstuvwxyz"; string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; vl dx={0,0,1,-1,1,1,-1,-1}; vl dy={1,-1,0,0,-1,1,-1,1}; template vector make_vec(size_t a) { return vector(a); } template auto make_vec(size_t a, Ts... ts) { return vector(ts...))>(a, make_vec(ts...)); } templatebool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(bdp(100100); P dfs(ll cur=0,ll par=-1){ ll ww=0,w=0; for(ll to:G[cur]){ if(par==to)continue; P p=dfs(to,cur); ww+=p.first; w+=p.second; } if(s[cur]=='w'){ ww+=w; w++; } return dp[cur]={ww,w}; } vectordp2(100100); void dfs2(ll cur=0,ll par=-1){ if(par!=-1){ ll w=dp[0].second-dp[cur].second; ll ww=dp2[par]-dp[cur].first-(s[par]=='w'?dp[cur].second:0); dp2[cur]=dp[cur].first+ww+(s[cur]=='w'?w:0); // if(cur==2)cout<>n; cin>>s; vectora(n-1),b(n-1); for(int i=0;i>a[i]>>b[i];a[i]--;b[i]--; G[a[i]].pb(b[i]); G[b[i]].pb(a[i]); } dfs(); dp2[0]=dp[0].first; dfs2(); ll ans=0; for(int i=0;i