結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー 沙耶花沙耶花
提出日時 2023-02-03 21:33:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 4,061 ms
コンパイル使用メモリ 261,980 KB
実行使用メモリ 28,148 KB
最終ジャッジ日時 2023-09-15 17:04:31
合計ジャッジ時間 10,636 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 160 ms
16,580 KB
testcase_12 AC 161 ms
16,420 KB
testcase_13 AC 155 ms
16,568 KB
testcase_14 AC 134 ms
16,532 KB
testcase_15 AC 175 ms
28,148 KB
testcase_16 AC 107 ms
11,248 KB
testcase_17 AC 106 ms
11,196 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 162 ms
16,232 KB
testcase_20 AC 165 ms
15,904 KB
testcase_21 AC 164 ms
15,620 KB
testcase_22 AC 151 ms
16,496 KB
testcase_23 AC 164 ms
15,668 KB
testcase_24 AC 162 ms
15,992 KB
testcase_25 AC 169 ms
15,592 KB
testcase_26 AC 182 ms
15,616 KB
testcase_27 AC 163 ms
16,232 KB
testcase_28 AC 150 ms
16,592 KB
testcase_29 AC 152 ms
16,868 KB
testcase_30 AC 187 ms
15,744 KB
testcase_31 AC 161 ms
16,500 KB
testcase_32 AC 165 ms
15,928 KB
testcase_33 AC 164 ms
15,948 KB
testcase_34 AC 160 ms
15,612 KB
testcase_35 AC 178 ms
15,672 KB
testcase_36 AC 182 ms
15,620 KB
testcase_37 AC 164 ms
15,668 KB
testcase_38 AC 182 ms
15,616 KB
testcase_39 AC 160 ms
16,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001
vector<vector<int>> E;
int ans = 0;
vector<int> c;

void dfs(int cv,int p){
	rep(i,E[cv].size()){
		int to = E[cv][i];
		if(to==p)continue;
		dfs(to,cv);
	}
	if(c[cv]==0 && p!=-1){
		c[cv] = 1;
		c[p] ^= 1;
		ans++;
	}
}

int main(){
	
	int n;
	cin>>n;
	
	E.resize(n);
	c.resize(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	rep(i,n)cin>>c[i];
	dfs(0,-1);
	if(c!=vector<int>(n,1))cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}
0