結果
問題 | No.2205 Lights Out on Christmas Tree |
ユーザー |
|
提出日時 | 2025-02-18 00:04:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 101 ms / 2,000 ms |
コード長 | 614 bytes |
コンパイル時間 | 1,617 ms |
コンパイル使用メモリ | 164,076 KB |
実行使用メモリ | 27,892 KB |
最終ジャッジ日時 | 2025-02-18 00:04:27 |
合計ジャッジ時間 | 5,884 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:26:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:30:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d%d",&a,&b); | ~~~~~^~~~~~~~~~~~~~ main.cpp:34:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | for(i=1;i<=n;i++) scanf("%d",&col[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int INF=0x3f3f3f3f;const int mod=1e9+7;const int MAX=2e5+10;vector<int> mp[MAX];int col[MAX],ans;void dfs(int x,int fa){for(auto &to:mp[x]){if(to==fa) continue;dfs(to,x);if(col[to]==0){col[to]^=1;col[x]^=1;ans++;}}}int main(){int n,i,a,b;scanf("%d",&n);for(i=1;i<=n;i++) mp[i].clear();for(i=1;i<n;i++){scanf("%d%d",&a,&b);mp[a].push_back(b);mp[b].push_back(a);}for(i=1;i<=n;i++) scanf("%d",&col[i]);ans=0;dfs(1,0);if(col[1]==0) ans=-1;printf("%d\n",ans);return 0;}