結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,356 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 157 ms
15,584 KB
testcase_12 AC 159 ms
15,852 KB
testcase_13 AC 152 ms
15,588 KB
testcase_14 AC 132 ms
15,536 KB
testcase_15 AC 166 ms
22,360 KB
testcase_16 AC 105 ms
10,800 KB
testcase_17 AC 104 ms
10,592 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 160 ms
15,352 KB
testcase_20 AC 162 ms
14,868 KB
testcase_21 AC 162 ms
14,812 KB
testcase_22 AC 148 ms
15,760 KB
testcase_23 AC 161 ms
14,872 KB
testcase_24 AC 160 ms
15,256 KB
testcase_25 AC 165 ms
14,812 KB
testcase_26 AC 177 ms
14,812 KB
testcase_27 AC 159 ms
15,408 KB
testcase_28 AC 148 ms
15,668 KB
testcase_29 AC 151 ms
15,968 KB
testcase_30 AC 176 ms
15,060 KB
testcase_31 AC 159 ms
15,600 KB
testcase_32 AC 160 ms
15,068 KB
testcase_33 AC 161 ms
15,140 KB
testcase_34 AC 158 ms
14,844 KB
testcase_35 AC 171 ms
14,700 KB
testcase_36 AC 171 ms
14,752 KB
testcase_37 AC 160 ms
14,700 KB
testcase_38 AC 178 ms
14,956 KB
testcase_39 AC 158 ms
15,284 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