結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー umezoumezo
提出日時 2023-02-05 06:38:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 2,692 ms
コンパイル使用メモリ 203,044 KB
実行使用メモリ 24,560 KB
最終ジャッジ日時 2023-09-17 01:00:28
合計ジャッジ時間 7,090 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,628 KB
testcase_01 AC 3 ms
9,656 KB
testcase_02 AC 3 ms
9,672 KB
testcase_03 AC 3 ms
9,600 KB
testcase_04 AC 3 ms
9,632 KB
testcase_05 AC 4 ms
9,632 KB
testcase_06 AC 3 ms
9,688 KB
testcase_07 AC 4 ms
9,616 KB
testcase_08 AC 4 ms
9,628 KB
testcase_09 AC 3 ms
9,604 KB
testcase_10 AC 3 ms
9,776 KB
testcase_11 AC 60 ms
17,272 KB
testcase_12 AC 59 ms
17,128 KB
testcase_13 AC 57 ms
17,228 KB
testcase_14 AC 56 ms
17,344 KB
testcase_15 AC 70 ms
24,560 KB
testcase_16 AC 44 ms
13,928 KB
testcase_17 AC 44 ms
13,916 KB
testcase_18 AC 4 ms
9,620 KB
testcase_19 AC 67 ms
16,912 KB
testcase_20 AC 69 ms
16,416 KB
testcase_21 AC 67 ms
16,420 KB
testcase_22 AC 59 ms
17,364 KB
testcase_23 AC 68 ms
16,312 KB
testcase_24 AC 67 ms
16,580 KB
testcase_25 AC 71 ms
16,296 KB
testcase_26 AC 80 ms
16,352 KB
testcase_27 AC 65 ms
17,100 KB
testcase_28 AC 58 ms
17,404 KB
testcase_29 AC 61 ms
17,372 KB
testcase_30 AC 78 ms
16,352 KB
testcase_31 AC 72 ms
17,144 KB
testcase_32 AC 66 ms
16,576 KB
testcase_33 AC 64 ms
16,620 KB
testcase_34 AC 61 ms
16,404 KB
testcase_35 AC 70 ms
16,356 KB
testcase_36 AC 68 ms
16,380 KB
testcase_37 AC 64 ms
16,488 KB
testcase_38 AC 78 ms
16,320 KB
testcase_39 AC 63 ms
16,920 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;

vector<int> G[200200];
int dp[200200][2];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  rep(i,200200) rep(j,2) dp[i][j]=-1;
  
  int n;
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> C(n);
  rep(i,n) cin>>C[i];
  
  auto dfs=[&](auto dfs,int v,int p)->void{
    int c=0;
    if(C[v]==0) c++;
    int sum=0;
    for(auto nv:G[v]){
      if(nv==p) continue;
      dfs(dfs,nv,v);
      if(dp[nv][1]!=-1){
        c++;
        sum+=dp[nv][1]+1;
      }
      else sum+=dp[nv][0];
    }
    if(c%2==0) dp[v][0]=sum;
    else dp[v][1]=sum;
  };
  
  dfs(dfs,0,-1);
  cout<<dp[0][0]<<endl;
  
  return 0;
}
0