mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-11 22:06:27 +00:00
parent
e7613a7db1
commit
105ce7cac4
33
S2OJ/440/440.cpp
Normal file
33
S2OJ/440/440.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n, l, k, root, dp[6005][2], p[6005];
|
||||
|
||||
void dfs(int x) {
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (p[i] == x) {
|
||||
dfs(i);
|
||||
dp[x][0] += max(dp[i][0], dp[i][1]);
|
||||
dp[x][1] += dp[i][0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> dp[i][1];
|
||||
}
|
||||
while (cin >> l >> k && (l != 0 && k != 0)) {
|
||||
p[l] = k;
|
||||
}
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (!p[i]) {
|
||||
root = i;
|
||||
}
|
||||
}
|
||||
dfs(root);
|
||||
cout << max(dp[root][0], dp[root][1]) << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user