BNUOJ 2461 Anniversary party
Anniversary party
This problem will be judged on PKU. Original ID: 2342
64-bit integer IO format: %lld Java class name: Main
Input
L K
It means that the K-th employee is an immediate supervisor of the L-th employee. Input is ended with the line
0 0
Output
Sample Input
7
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5
0 0
Sample Output
5
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
int dp[maxn][],w[maxn],n,in[maxn];
vector<int>g[maxn];
void dfs(int u,int fa){
dp[u][] = w[u];
for(int i = ; i < g[u].size(); i++){
if(g[u][i] == fa) continue;
dfs(g[u][i],u);
dp[u][] += dp[g[u][i]][];//u来,g[u][i]不来
dp[u][] += max(dp[g[u][i]][],dp[g[u][i]][]);
//u不来,g[u][i]来或者不来
}
}
int main() {
int i,j,u,v,tmp;
while(~scanf("%d",&n)){
for(i = ; i <= n; i++){
scanf("%d",w+i);
g[i].clear();
in[i] = ;
dp[i][] = dp[i][] = ;
}
for(i = ; i; i++){
scanf("%d %d",&u,&v);
if(u+v == ) break;
g[u].push_back(v);
g[v].push_back(u);
in[v]++;
}
for(i = ; i <= n; i++){
if(!in[i]){dfs(i,-);break;}
}
printf("%d\n",max(dp[i][],dp[i][]));
}
return ;
}
BNUOJ 2461 Anniversary party的更多相关文章
- (UWP开发)基于Windows10 Anniversary SDK创造出位于可视化层的DropShadow
Windows.UI.Composition API是可以从任何通用Windows平台应用程序调用的声明性保留模式API,从而可以直接在应用程序中创建合成对象.动画和效果. Composition A ...
- POJ 2342 Anniversary party(树形dp)
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7230 Accepted: 4162 ...
- 微软四十周年 Microsoft’s 40th anniversary
比尔-盖茨在4月3日给微软全体员工写了这封邮件,原文是英文,我们翻译了中文.图片是后加上的. 明天将是特殊的一天:微软的40周年纪念日. Tomorrow is a special day: Micr ...
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- HDOJ 1520 Anniversary party
树形DP....在树上做DP....不应该是猴子干的事吗? Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hdu1520 树形dp Anniversary party
A - Anniversary party Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- bnuoj 24251 Counting Pair
一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...
- hdu 1520 Anniversary party 基础树dp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 【Poj】 p2342 Anniversary party(树形DP第一道)
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5523 Accepted: 3169 ...
随机推荐
- J20170616-hm
所以(ゆえん) 理由,原因,来由
- event.target 属性返回哪个 DOM 元素触发了事件。
<ul> <li>list <strong>item 1</strong></li> <li><span>list ...
- jQuery——表单应用(3)
HTML: <!--表单-多行文本框应用-滚动条高度变化--> <!DOCTYPE html> <html> <head> <meta chars ...
- Asp.NET 知识点总结(一)
1.简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有类,私有成员, 在类的内部才可以访问. protected : ...
- 转 Shell调试篇
检查语法 -n选项只做语法检查,而不执行脚本. sh -n script_name.sh 启动调试 sh -x script_name.sh 进入调试模式后,Shell依次执行读入的语句,产生的输出中 ...
- 373 Find K Pairs with Smallest Sums 查找和最小的K对数字
给定两个以升序排列的整形数组 nums1 和 nums2, 以及一个整数 k.定义一对值 (u,v),其中第一个元素来自 nums1,第二个元素来自 nums2.找到和最小的 k 对数字 (u1,v1 ...
- SqlServer数据库(可疑)解决办法
-- 当数据库发生这种操作故障时,可以按如下操作步骤可解决此方法,打开数据库里的Sql 查询编辑器窗口,运行以下的命令. --1.修改数据库为紧急模式 ALTER DATABASE Zhangxing ...
- Eclipse里的Java EE视图在哪里?MyEclipse里的Java EE视图在哪里?MyEclipse里的MyEclipse Java Enterprise视图在哪里?(图文详解)
为什么要写这篇博客呢? 是因为,最近接触一个web项目. 然后呢,Eclipse里的Java EE视图的位置与MyEclipse里不太一样.为了自己梳理日后查找,也是为了新手少走弯路. Eclipse ...
- JavaScript(第二部分)
一.DOM获取元素节点的子节点 1.getElementsByTagName() 返回当前节点的指定标签名子节点 2.childNodes 表示当前节点的所有子节点 3.firstChild ...
- java多线程之内存的可见性介绍(备用1)
(仅供参考) a.共享变量的可见能够一定程度保证线程安全,共享变量不可见导致数据不够准确,出现各种各样的问题,导致线程不安全. b.不同线程之间无法直接访问其他线程工作内存中的变量. 1.可见性 2. ...