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 ...
随机推荐
- MySQL Archive存储引擎
200 ? "200px" : this.width)!important;} --> 介绍 从archive单词的解释我们大概可以明白这个存储引擎的用途,这个存储引擎基本上 ...
- bzoj 1718: [Usaco2006 Jan] Redundant Paths 分离的路径【tarjan】
首先来分析一下,这是一张无向图,要求没有两条路联通的点对个数 有两条路连通,无向图,也就是说,问题转化为不在一个点双连通分量里的点对个数 tarjan即可,和求scc还不太一样-- #include& ...
- [C++ STL] 各容器简单介绍
什么是STL? 1.STL(Standard Template Library),即标准模板库,是一个高效的C++程序库. 2.包含了诸多常用的基本数据结构和基本算法.为广大C++程序员们提供了一个可 ...
- [转]微信开发.Net 接入示例
本文转自:http://my.oschina.net/lcak/blog/219618 微信公众平台接口开发官方仅提供了 PHP 接入示例代码, 网上找到的.Net代码多半需要积分下载, 所以自己写了 ...
- Java 8 (9) Optional取代null
NullPointerException,大家应该都见过.这是Tony Hoare在设计ALGOL W语言时提出的null引用的想法,他的设计初衷是想通过编译器的自动检测机制,确保所有使用引用的地方都 ...
- WCF学习笔记(1)-一个完整的例子
一.开发环境 IDE:VS2013 OS:Win10 IIS:IIS 10 二.开发流程 1.项目结构 2.添加一个WCF程序 3.删除系统自动生成的两个文件IService1.cs和Service1 ...
- 60使用nanopim1plus查看HDMI显示分辨率的问题(分色排版)V1.0
60使用nanopim1plus查看HDMI显示分辨率的问题(分色排版)V1.0 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 21504965 AT qq.com 完成时间:2017/12/5 17: ...
- 计算机二级C语言冲刺笔记。
2018-03-0618:32:26 风萧萧兮易水寒,壮士一去...... 四级依旧没过,计算机二级接踵而至, default语句在switch语句中可以省略,所以B错误:switch语句中并非每个c ...
- win7 中使用NFS共享
转自和修改自:http://blog.sina.com.cn/s/blog_553761ef0100oevm.html 一 安装 在卸载或更改程序->打开或关闭windows的功能-> 安 ...
- Spring+Spring MVC+Hibernate增查(使用注解)
使用Spring+Spring MVC+Hibernate做增删改查开发效率真的很高.使用Hibernate简化了JDBC连接数据库的的重复性代码.下面根据自己做的一个简单的增加和查询,把一些难点分析 ...