結果
| 問題 |
No.2205 Lights Out on Christmas Tree
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-02-18 00:05:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 2,000 ms |
| コード長 | 614 bytes |
| コンパイル時間 | 1,775 ms |
| コンパイル使用メモリ | 193,980 KB |
| 実行使用メモリ | 27,884 KB |
| 最終ジャッジ日時 | 2025-02-18 00:05:21 |
| 合計ジャッジ時間 | 5,691 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
}
vjudge1