結果

問題 No.2377 SUM AND XOR on Tree
ユーザー umezoumezo
提出日時 2023-07-07 23:14:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 387 ms / 4,000 ms
コード長 1,107 bytes
コンパイル時間 2,205 ms
コンパイル使用メモリ 209,108 KB
実行使用メモリ 14,776 KB
最終ジャッジ日時 2023-09-29 00:57:31
合計ジャッジ時間 10,526 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,428 KB
testcase_01 AC 6 ms
7,264 KB
testcase_02 AC 6 ms
7,288 KB
testcase_03 AC 7 ms
7,276 KB
testcase_04 AC 7 ms
7,432 KB
testcase_05 AC 6 ms
7,284 KB
testcase_06 AC 7 ms
7,260 KB
testcase_07 AC 7 ms
7,272 KB
testcase_08 AC 296 ms
11,076 KB
testcase_09 AC 352 ms
10,956 KB
testcase_10 AC 325 ms
10,952 KB
testcase_11 AC 387 ms
10,956 KB
testcase_12 AC 359 ms
10,900 KB
testcase_13 AC 343 ms
11,032 KB
testcase_14 AC 315 ms
10,628 KB
testcase_15 AC 330 ms
10,988 KB
testcase_16 AC 310 ms
10,896 KB
testcase_17 AC 336 ms
11,080 KB
testcase_18 AC 7 ms
7,352 KB
testcase_19 AC 7 ms
7,500 KB
testcase_20 AC 7 ms
7,296 KB
testcase_21 AC 7 ms
7,300 KB
testcase_22 AC 7 ms
7,512 KB
testcase_23 AC 322 ms
10,916 KB
testcase_24 AC 348 ms
11,128 KB
testcase_25 AC 357 ms
10,900 KB
testcase_26 AC 135 ms
14,736 KB
testcase_27 AC 133 ms
14,688 KB
testcase_28 AC 136 ms
14,776 KB
testcase_29 AC 110 ms
11,196 KB
testcase_30 AC 110 ms
11,204 KB
testcase_31 AC 110 ms
11,380 KB
testcase_32 AC 116 ms
10,980 KB
testcase_33 AC 115 ms
10,908 KB
testcase_34 AC 115 ms
10,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MOD=998244353;
vector<int> G[100100];
ll dp[100100][2];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  vector<ll> B(30);
  B[0]=1;
  rep(i,29) B[i+1]=B[i]*2%MOD;

  int n;
  cin>>n;
  rep(i,n-1){
    int u,v;
    cin>>u>>v;
    u--,v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  
  auto f=[&](auto f,int v,int p,int i)->void{
    int cnt=0;
    for(auto nv:G[v]){
      if(nv==p) continue;
      cnt++;
    }
    if(A[v]&(1LL<<i)) dp[v][1]=1;
    else dp[v][0]=1;
    for(auto nv:G[v]){
      if(nv==p) continue;
      f(f,nv,v,i);
      ll t0=dp[v][0],t1=dp[v][1];
      dp[v][0]=(t0*(dp[nv][0]+dp[nv][1])%MOD+t1*dp[nv][1]%MOD)%MOD;
      dp[v][1]=(t1*(dp[nv][0]+dp[nv][1])%MOD+t0*dp[nv][1]%MOD)%MOD;
    }
  };
  
  ll ans=0;
  rep(i,30){
    rep(j,100100) rep(k,2) dp[j][k]=0;
    f(f,0,-1,i);
    ans=(ans+dp[0][1]*B[i]%MOD)%MOD;
  }
  cout<<ans<<endl;

  return 0;
}
0