結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー ゆにぽけゆにぽけ
提出日時 2023-10-14 13:07:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 932 bytes
コンパイル時間 1,231 ms
コンパイル使用メモリ 127,404 KB
実行使用メモリ 31,980 KB
最終ジャッジ日時 2023-10-14 13:07:47
合計ジャッジ時間 10,151 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,576 KB
testcase_01 AC 3 ms
11,576 KB
testcase_02 AC 3 ms
11,760 KB
testcase_03 AC 3 ms
11,612 KB
testcase_04 AC 3 ms
11,564 KB
testcase_05 AC 3 ms
11,556 KB
testcase_06 AC 3 ms
11,564 KB
testcase_07 AC 3 ms
11,568 KB
testcase_08 AC 3 ms
11,576 KB
testcase_09 AC 3 ms
11,624 KB
testcase_10 AC 3 ms
11,688 KB
testcase_11 AC 67 ms
18,596 KB
testcase_12 AC 68 ms
18,396 KB
testcase_13 AC 66 ms
18,428 KB
testcase_14 AC 62 ms
18,396 KB
testcase_15 AC 86 ms
31,980 KB
testcase_16 AC 52 ms
16,160 KB
testcase_17 AC 50 ms
16,160 KB
testcase_18 AC 5 ms
11,556 KB
testcase_19 AC 102 ms
18,904 KB
testcase_20 AC 84 ms
18,956 KB
testcase_21 AC 83 ms
18,908 KB
testcase_22 AC 67 ms
18,976 KB
testcase_23 AC 77 ms
18,540 KB
testcase_24 AC 76 ms
18,872 KB
testcase_25 AC 85 ms
19,000 KB
testcase_26 AC 92 ms
19,328 KB
testcase_27 AC 75 ms
18,804 KB
testcase_28 AC 65 ms
18,868 KB
testcase_29 AC 68 ms
18,924 KB
testcase_30 AC 91 ms
19,296 KB
testcase_31 AC 67 ms
18,976 KB
testcase_32 AC 67 ms
19,228 KB
testcase_33 AC 70 ms
19,156 KB
testcase_34 AC 69 ms
18,512 KB
testcase_35 AC 91 ms
19,204 KB
testcase_36 AC 76 ms
19,480 KB
testcase_37 AC 70 ms
18,408 KB
testcase_38 AC 83 ms
19,316 KB
testcase_39 AC 65 ms
19,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
using namespace std;
int N,C[2 << 17],W[2 << 17];
vector<int> G[2 << 17];
long long dp[2 << 17];
void dfs(int u,int p)
{
	if(C[u]) W[u] = 1;
	for(int v:G[u])if(v != p)
	{
		dfs(v,u);
		dp[u] += dp[v];
		if(W[v]%2 == 1) dp[u]++;
		W[u] += W[v];
	}
}
void solve()
{
	cin >> N;
	for(int i = 1;i < N;i++)
	{
		int u,v;
		cin >> u >> v;
		u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i = 0;i < N;i++) cin >> C[i],C[i] ^= 1;
	dfs(0,-1);
	if(W[0]%2 == 1) cout << -1 << endl;
	else cout << dp[0] << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
}
0