# 某島

… : "…アッカリ～ン . .. . " .. .
March 10, 2020

## POJ 2342. Anniversary party

f0 表示當前節點不取
f1 表示當前節點取

```const int N = int(1e4) + 9;
int f0[N], f1[N]; // 不取, 取
int n, p;

void dfs(int u = 0, int p = -1) {
#define v (*it)
ECH(it, adj[u]) if (v != p) {
dfs(v, u);
f0[u] += max(f0[v], f1[v]);
f1[u] += f0[v];
}
}

int main() {

#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif

while (RD(n)) {
REP(i, n) RDD(f1[i]), f0[i] = 0, adj[i].clear();

DO (n-1) {
int x, y; RD(x, y); --x; --y;
}
dfs();
cout << max(f0[0],f1[0]) << endl;
}
}
```

```const int N = int(1e4) + 9;
int f0[N], f1[N]; // 不取, 取 or 不取
int n, p;

void dfs(int u = 0, int p = -1) {
#define v (*it)
ECH(it, adj[u]) if (v != p) {
dfs(v, u);
f0[u] += f1[v];
f1[u] += f0[v];
}
checkMax(f1[u], f0[u]);
}

int main() {

#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif

while (RD(n)) {
REP(i, n) RDD(f1[i]), f0[i] = 0, adj[i].clear();

DO (n-1) {
int x, y; RD(x, y); --x; --y;