树形最大上升子序列

这里面的上生子序列logn的地方能当模板使  good

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
const int maxa = ;
vector<int>e[maxa];
int d[maxa];
int a[maxa];
int mx, n;
void dfs(int q, int p){
int k = lower_bound(d, d+n, a[q]) - d;
mx = max(mx, k);
int t = d[k];
d[k] = a[q];
for(int i = ; i < e[q].size(); i++){
if(e[q][i]!=p)
dfs(e[q][i], q);
}
d[k] = t;
}
int main(){
cin>>n;
for(int i = ; i <= n; i++)scanf("%d", a+i);
for(int i = ; i < n; i++){int x, y;
scanf("%d%d", &x, &y);
e[x].push_back(y);
e[y].push_back(x);
}
for(int i =; i <= n; i++)d[i] = (<<);
for(int i = ; i <= n; i++){
dfs(i, );
}printf("%d\n", mx+);
}

Codeforces Round #279 (Div. 2)f的更多相关文章

  1. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  2. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  3. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  4. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  5. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  6. Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)

    题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...

  7. Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)

    题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...

  8. Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid

    F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  9. Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)

    题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...

随机推荐

  1. Android Framework------之ActivityManagerService与Activity之间的通信

    研究Android系统的童鞋,想必都已经了解一个Activity的启动过程了.而且在网上,关于Activity的启动的文章非常多,很容易就能找到的.这篇文章的重点放在ActivityManagerSe ...

  2. xPath技术

    在dom4j中如何使用xPath技术 1)导入xPath支持jar包 . jaxen-1.1-beta-6.jar 2)使用xpath方法 List<Node> selectNodes(& ...

  3. 『邪恶のWIFI』搭建假冒WIFI热点等女神来蹭网啊 - -。

    pic by baidu 0x 00 ╮(╯▽╰)╭ 请喊我万恶的标题党  哈哈哈哈哈 0x 01 这里正题 虚拟机(Kali)不支持内置网卡,还好我有神器,插上我的RT8187L,开始搞起 参考资料 ...

  4. sizeof用法研究

    一.基础研究 写一个c程序,打印int.long.double型变量所占的字节数.地址.各个字节的地址和内容.打印地址和内容比较好办,打印地址可以用取址符&,打印内容直接输出就行了,那么怎么打 ...

  5. angularjs 1.3 综合学习 (one way bind , ng-if , ng-switch , ng-messages, ng-form ,ng-model )

    主要讲解1.3后的一些新功能,和一些以前没有介绍的小功能 (ng-if,ng-switch). 1.one way bind 这个之前的版本已经有人自己实现了,但是在1.3之后,angularjs 有 ...

  6. Linux下根据进程的名字杀死进程

    以前是写了一个bash,通过ps,grep 和awk配合搜索PID再kill掉进程.果然以前傻,不知道解决问题之前先google,原来直接就有相关的pkill -f "process_nam ...

  7. row cache lock

    SQL> col name format a30 SQL> select * from (select SAMPLE_TIME, SESSION_ID, NAME, P1, P2, P3, ...

  8. JQ无法修改input的type属性的替代解决方法

    需要实现的效果:一个输入框,当输入框未获得焦点的时候,显示为 “请输入密码”:当输入内容并失去焦点的时候,输入内容显示为”*****”,如果没有输入仍然显示“请输入密码”: 方法一:使用text,隐藏 ...

  9. Android样式的编写格式

    <?xml version="1.0" encoding="utf-8"?> <resources> <style name=&q ...

  10. HDU_2018——母牛产小牛的问题,递推

    Problem Description 有一头母牛,它每年年初生一头小母牛.每头小母牛从第四个年头开始,每年年初也生一头小母牛.请编程实现在第n年的时候,共有多少头母牛?   Input 输入数据由多 ...