結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー i_am_noobi_am_noob
提出日時 2023-02-15 18:36:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 691 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 201,272 KB
実行使用メモリ 27,576 KB
最終ジャッジ日時 2023-09-25 03:02:35
合計ジャッジ時間 9,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,060 KB
testcase_01 AC 5 ms
8,124 KB
testcase_02 AC 4 ms
8,120 KB
testcase_03 AC 5 ms
8,116 KB
testcase_04 AC 4 ms
8,048 KB
testcase_05 AC 4 ms
8,120 KB
testcase_06 AC 4 ms
8,332 KB
testcase_07 AC 5 ms
8,120 KB
testcase_08 AC 4 ms
8,112 KB
testcase_09 AC 4 ms
8,332 KB
testcase_10 AC 4 ms
8,092 KB
testcase_11 AC 67 ms
15,584 KB
testcase_12 AC 67 ms
15,700 KB
testcase_13 AC 65 ms
15,580 KB
testcase_14 AC 62 ms
15,724 KB
testcase_15 AC 81 ms
27,576 KB
testcase_16 AC 50 ms
12,696 KB
testcase_17 AC 49 ms
12,700 KB
testcase_18 AC 4 ms
8,124 KB
testcase_19 AC 73 ms
15,728 KB
testcase_20 AC 73 ms
15,092 KB
testcase_21 AC 75 ms
15,088 KB
testcase_22 AC 65 ms
16,152 KB
testcase_23 AC 73 ms
15,092 KB
testcase_24 AC 73 ms
15,628 KB
testcase_25 AC 76 ms
15,284 KB
testcase_26 AC 91 ms
15,112 KB
testcase_27 AC 73 ms
15,888 KB
testcase_28 AC 65 ms
16,152 KB
testcase_29 AC 67 ms
16,264 KB
testcase_30 AC 92 ms
15,252 KB
testcase_31 AC 72 ms
15,916 KB
testcase_32 AC 74 ms
15,412 KB
testcase_33 AC 74 ms
15,400 KB
testcase_34 AC 73 ms
15,288 KB
testcase_35 AC 88 ms
15,212 KB
testcase_36 AC 87 ms
15,160 KB
testcase_37 AC 73 ms
15,360 KB
testcase_38 AC 73 ms
15,092 KB
testcase_39 AC 71 ms
15,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;

#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())

const int maxn=200005;
int n,a[maxn],res;
vector<int> adj[maxn];

void dfs(int u, int par){
    for(auto v: adj[u]) if(v!=par) dfs(v,u),a[u]^=a[v];
    res+=a[u];
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    for(int i=0; i<n-1; ++i){
        int u,v; cin >> u >> v; u--,v--;
        adj[u].pb(v),adj[v].pb(u);
    }
    for(int i=0; i<n; ++i) cin >> a[i],a[i]^=1;
    if(count(a,a+n,1)&1){
        cout << "-1\n";
        return 0;
    }
    dfs(0,-1);
    cout << res << "\n";
}
0