记录编号 |
543838 |
评测结果 |
AAAAAAAAAA |
题目名称 |
没有上司的舞会 |
最终得分 |
100 |
用户昵称 |
牛掰格拉斯 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.027 s |
提交时间 |
2019-10-10 21:01:25 |
内存使用 |
13.89 MiB |
显示代码纯文本
- //2019.10.10
- #include<bits/stdc++.h>
- using namespace std;
- vector<int> tree[6001];
- int n,root=1;
- int dp[6001][2];//dp[i][1]表示取这个点,dp[i][0]表示不取
- int father[6001],happy[6001];
- void findroot()
- {
- while(father[root]!=-1) root=father[root];
- }
- void dfs(int u)
- {
- dp[u][0]=0;
- dp[u][1]=happy[u];
- for(int i=0;i<tree[u].size();i++)
- {
- int son=tree[u][i];
- dfs(son);
- dp[u][1]+=dp[son][0];
- dp[u][0]+=max(dp[son][0],dp[son][1]);
- }
- }
- int main()
- {
- freopen("partyy.in","r",stdin);
- freopen("partyy.out","w",stdout);
- cin>>n;
- for(int i=1;i<=n;i++)
- {
- cin>>happy[i];
- father[i]=-1;
- }
- while(true)
- {
- int x,y;
- cin>>x>>y;
- if(x==0&&y==0) break;
- tree[y].push_back(x);
- father[x]=y;
- }
- findroot();
- dfs(root);
- cout<<max(dp[root][0],dp[root][1]);
- return 0;
- }