結果
| 問題 |
No.2205 Lights Out on Christmas Tree
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2023-02-03 22:08:55 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 87 ms / 2,000 ms |
| コード長 | 1,120 bytes |
| コンパイル時間 | 133 ms |
| コンパイル使用メモリ | 29,696 KB |
| 実行使用メモリ | 23,652 KB |
| 最終ジャッジ日時 | 2024-07-02 20:07:56 |
| 合計ジャッジ時間 | 4,204 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#include <stdio.h>
typedef struct list {
int v;
struct list *n;
} list;
int func (int v, list **e, int *c, int *visited) {
list *l = e[v];
int ans = 0;
visited[v] = 1;
while (l != NULL) {
if (visited[l->v] <= 0) {
ans += func(l->v, e, c, visited);
if (c[l->v] <= 0) {
ans++;
c[l->v] = 1;
c[v] = 1-c[v];
}
}
l = l->n;
}
return ans;
}
int main () {
int n = 0;
int a = 0;
int b = 0;
int c[200000] = {};
int res = 0;
int ans = 0;
int visited[200000] = {};
list pool[399998] = {};
int used = 0;
list *e[200000] = {};
res = scanf("%d", &n);
for (int i = 0; i < n-1; i++) {
res = scanf("%d", &a);
res = scanf("%d", &b);
a--;
b--;
pool[used].v = b;
pool[used].n = e[a];
e[a] = pool+used;
used++;
pool[used].v = a;
pool[used].n = e[b];
e[b] = pool+used;
used++;
}
for (int i = 0; i < n; i++) {
res = scanf("%d", c+i);
}
ans = func(0, e, c, visited);
if (c[0] > 0) {
printf("%d\n", ans);
} else {
printf("-1\n");
}
return 0;
}
chro_96