树形最大上升子序列
这里面的上生子序列logn的地方能当模板使 good
#include<iostream> #include<string.h> #include<stdio.h> #include<algorithm> #include<vector> using namespace std; const int maxa = 6006; 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 = 0; 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 = 1; i <= n; i++)scanf("%d", a+i); for(int i = 1; i < n; i++){int x, y; scanf("%d%d", &x, &y); e[x].push_back(y); e[y].push_back(x); } for(int i =0; i <= n; i++)d[i] = (1<<30); for(int i = 1; i <= n; i++){ dfs(i, 0); }printf("%d ", mx+1); }