結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-07-13 07:50:03
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 2,817 ms
コンパイル使用メモリ 250,912 KB
実行使用メモリ 22,520 KB
最終ジャッジ日時 2023-10-12 21:16:45
合計ジャッジ時間 9,120 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 158 ms
15,616 KB
testcase_12 AC 159 ms
15,580 KB
testcase_13 AC 153 ms
15,636 KB
testcase_14 AC 132 ms
15,536 KB
testcase_15 AC 166 ms
22,520 KB
testcase_16 AC 106 ms
10,700 KB
testcase_17 AC 104 ms
10,620 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 161 ms
15,296 KB
testcase_20 AC 161 ms
14,800 KB
testcase_21 AC 161 ms
14,808 KB
testcase_22 AC 149 ms
15,564 KB
testcase_23 AC 161 ms
14,872 KB
testcase_24 AC 160 ms
15,080 KB
testcase_25 AC 164 ms
14,872 KB
testcase_26 AC 176 ms
14,856 KB
testcase_27 AC 160 ms
15,344 KB
testcase_28 AC 148 ms
15,844 KB
testcase_29 AC 150 ms
15,860 KB
testcase_30 AC 175 ms
14,928 KB
testcase_31 AC 160 ms
15,544 KB
testcase_32 AC 162 ms
15,308 KB
testcase_33 AC 160 ms
15,104 KB
testcase_34 AC 159 ms
14,772 KB
testcase_35 AC 170 ms
14,764 KB
testcase_36 AC 170 ms
14,800 KB
testcase_37 AC 163 ms
14,860 KB
testcase_38 AC 181 ms
14,772 KB
testcase_39 AC 159 ms
15,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
 
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define db double
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
	int n;cin>>n;
	vc v(n,vc<int>(0));
	rep(i,n-1){
		int a,b;cin>>a>>b; a--;b--;
		v[a].pb(b); v[b].pb(a);
	}
	vc<int>c(n); rep(i,n)cin>>c[i];
	auto f=[&](auto f,int a,int p)->pp{
	    int res=0,now=c[a];
	    for(auto au:v[a])if(au!=p){
	    	auto [x,y]=f(f,au,a);
	    	res+=x;
	    	now^=y;
	    }
	    if(now==0)return {res+1,1};
	    else return {res,0};
	};
	auto [ans,zz]=f(f,0,-1);
	if(zz)cout<<-1;
	else cout<<ans;
}
	
0