CF490F.Treeland Tour

提高+/省选-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The "Road Accident" band is planning an unprecedented tour around Treeland. The RA fans are looking forward to the event and making bets on how many concerts their favorite group will have.

Treeland consists of n cities, some pairs of cities are connected by bidirectional roads. Overall the country has n - 1 roads. We know that it is possible to get to any city from any other one. The cities are numbered by integers from 1 to n. For every city we know its value r__i — the number of people in it.

We know that the band will travel along some path, having concerts in some cities along the path. The band's path will not pass one city twice, each time they move to the city that hasn't been previously visited. Thus, the musicians will travel along some path (without visiting any city twice) and in some (not necessarily all) cities along the way they will have concerts.

The band plans to gather all the big stadiums and concert halls during the tour, so every time they will perform in a city which population is larger than the population of the previously visited with concert city. In other words, the sequence of population in the cities where the concerts will be held is strictly increasing.

In a recent interview with the leader of the "road accident" band promised to the fans that the band will give concert in the largest possible number of cities! Thus the band will travel along some chain of cities of Treeland and have concerts in some of these cities, so that the population number will increase, and the number of concerts will be the largest possible.

The fans of Treeland are frantically trying to figure out how many concerts the group will have in Treeland. Looks like they can't manage without some help from a real programmer! Help the fans find the sought number of concerts.

“道路事故”乐队正计划在树国(Treeland)展开一场史无前例的巡演。该乐队的粉丝们翘首以盼,并纷纷下注猜测自己最喜爱的乐队将在多少座城市举办演唱会。

树国由 nn 座城市组成,其中某些城市对之间由双向道路连接。全国总共拥有 n−1n-1 条道路。已知任意两座城市之间均可相互到达(即图是连通的)。城市编号为 11 至 nn 的整数。对每座城市 ii,我们已知其人口数 rir_i。

已知乐队将沿某条路径旅行,并在该路径上的若干城市中举办演唱会。乐队的行进路径不会重复经过同一座城市,即每次移动都前往一座此前未访问过的城市。因此,乐手们将沿某条简单路径(不重复访问任何城市)行进,并在该路径上若干(不一定全部)城市中举办演唱会。

乐队计划在巡演期间汇集所有大型体育场和音乐厅,因此他们只会在人口数严格大于上一个举办过演唱会的城市的人口数的城市中举办演唱会。换言之,所有举办演唱会的城市的人口数序列必须是严格递增的。

在最近一次接受采访时,“道路事故”乐队的主唱向粉丝们承诺:乐队将在尽可能多的城市举办演唱会!因此,乐队将选择树国中某条城市链(即一条简单路径),并在该路径上的若干城市中举办演唱会,使得对应的人口数序列严格递增,且演唱会总场次达到最大可能值。

树国的粉丝们正焦灼地试图推算出乐队最终将在树国举办多少场演唱会。看来,他们急需一位真正程序员的帮助!请帮助粉丝们找出所求的演唱会场次数。

输入格式

The first line of the input contains integer n (2 ≤ n ≤ 6000) — the number of cities in Treeland. The next line contains n integers _r_1, _r_2, ..., r__n (1 ≤ r__i ≤ 106), where r__i is the population of the i-th city. The next n - 1 lines contain the descriptions of the roads, one road per line. Each road is defined by a pair of integers a__j, b__j (1 ≤ a__j, b__j ≤ n) — the pair of the numbers of the cities that are connected by the j-th road. All numbers in the lines are separated by spaces.

输入的第一行包含一个整数 nn(2≤n≤60002 \leq n \leq 6000)—— 表示 Treeland 中城市的数量。
第二行包含 nn 个整数 r1,r2,…,rnr_1, r_2, \dots, r_n(1≤ri≤1061 \leq r_i \leq 10^6),其中 rir_i 表示第 ii 个城市的 population(人口)。
接下来的 n−1n-1 行描述了道路,每行描述一条道路。每条道路由一对整数 aj,bja_j, b_j(1≤aj,bj≤n1 \leq a_j, b_j \leq n)定义——表示第 jj 条道路所连接的两个城市的编号。
每行中的所有数字均以空格分隔。

输出格式

Print the number of cities where the "Road Accident" band will have concerts.

打印“道路事故”乐队将举办演唱会的城市数量。

输入输出样例

  • 输入#1

    6
    1 2 3 4 5 1
    1 2
    2 3
    3 4
    3 5
    3 6

    输出#1

    4
  • 输入#2

    5
    1 2 3 4 5
    1 2
    1 3
    2 4
    3 5

    输出#2

    3

输入解题思路,AI测评打分。不知道怎么写?

首页