#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=5e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-4;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
int cur;
vector<int> g[maxn];
int ans=0;
int dp[maxn];
vector<pii> v;
int arr[maxn];
void dfs(int u,int p,int d){
MXTO(dp[v[cur].s],dp[u]+d);
for(int x:g[u]){
if(x==p) continue;
if(arr[x]>cur) continue;
dfs(x,u,d+1);
}
}
int main(){
int n;
cin>>n;
REP(i,n){
int x;
cin>>x;
--x;
v.pb({x,i});
arr[i]=x;
}
REP(i,n-1){
int a,b;
cin>>a>>b;
--a,--b;
g[a].pb(b),g[b].pb(a);
}
sort(ALL(v));
for(auto x:v){
cur=x.f;
ans=0;
dfs(x.s,-1,0);
//cout<<dp[x.s]<<' ';
}
cout<<dp[v.back().s];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12060 KB |
Output is correct |
5 |
Correct |
7 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12060 KB |
Output is correct |
8 |
Correct |
7 ms |
12056 KB |
Output is correct |
9 |
Correct |
7 ms |
12056 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12060 KB |
Output is correct |
5 |
Correct |
7 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12060 KB |
Output is correct |
8 |
Correct |
7 ms |
12056 KB |
Output is correct |
9 |
Correct |
7 ms |
12056 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
7 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
12060 KB |
Output is correct |
13 |
Correct |
6 ms |
12088 KB |
Output is correct |
14 |
Correct |
9 ms |
12056 KB |
Output is correct |
15 |
Correct |
8 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
12056 KB |
Output is correct |
17 |
Correct |
7 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12060 KB |
Output is correct |
5 |
Correct |
7 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12060 KB |
Output is correct |
8 |
Correct |
7 ms |
12056 KB |
Output is correct |
9 |
Correct |
7 ms |
12056 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
7 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
12060 KB |
Output is correct |
13 |
Correct |
6 ms |
12088 KB |
Output is correct |
14 |
Correct |
9 ms |
12056 KB |
Output is correct |
15 |
Correct |
8 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
12056 KB |
Output is correct |
17 |
Correct |
7 ms |
11988 KB |
Output is correct |
18 |
Correct |
121 ms |
12620 KB |
Output is correct |
19 |
Correct |
105 ms |
12656 KB |
Output is correct |
20 |
Correct |
98 ms |
12592 KB |
Output is correct |
21 |
Correct |
12 ms |
12500 KB |
Output is correct |
22 |
Correct |
13 ms |
12500 KB |
Output is correct |
23 |
Correct |
12 ms |
12456 KB |
Output is correct |
24 |
Correct |
11 ms |
12500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12060 KB |
Output is correct |
5 |
Correct |
7 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12060 KB |
Output is correct |
8 |
Correct |
7 ms |
12056 KB |
Output is correct |
9 |
Correct |
7 ms |
12056 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
7 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
12060 KB |
Output is correct |
13 |
Correct |
6 ms |
12088 KB |
Output is correct |
14 |
Correct |
9 ms |
12056 KB |
Output is correct |
15 |
Correct |
8 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
12056 KB |
Output is correct |
17 |
Correct |
7 ms |
11988 KB |
Output is correct |
18 |
Correct |
121 ms |
12620 KB |
Output is correct |
19 |
Correct |
105 ms |
12656 KB |
Output is correct |
20 |
Correct |
98 ms |
12592 KB |
Output is correct |
21 |
Correct |
12 ms |
12500 KB |
Output is correct |
22 |
Correct |
13 ms |
12500 KB |
Output is correct |
23 |
Correct |
12 ms |
12456 KB |
Output is correct |
24 |
Correct |
11 ms |
12500 KB |
Output is correct |
25 |
Correct |
7 ms |
11972 KB |
Output is correct |
26 |
Correct |
116 ms |
12624 KB |
Output is correct |
27 |
Correct |
119 ms |
12560 KB |
Output is correct |
28 |
Correct |
118 ms |
12552 KB |
Output is correct |
29 |
Correct |
119 ms |
12540 KB |
Output is correct |
30 |
Correct |
18 ms |
12328 KB |
Output is correct |
31 |
Correct |
23 ms |
12244 KB |
Output is correct |
32 |
Correct |
20 ms |
12372 KB |
Output is correct |
33 |
Correct |
21 ms |
12244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12060 KB |
Output is correct |
5 |
Correct |
7 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12060 KB |
Output is correct |
8 |
Correct |
7 ms |
12056 KB |
Output is correct |
9 |
Correct |
7 ms |
12056 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
7 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
12060 KB |
Output is correct |
13 |
Correct |
6 ms |
12088 KB |
Output is correct |
14 |
Correct |
9 ms |
12056 KB |
Output is correct |
15 |
Correct |
8 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
12056 KB |
Output is correct |
17 |
Correct |
7 ms |
11988 KB |
Output is correct |
18 |
Correct |
121 ms |
12620 KB |
Output is correct |
19 |
Correct |
105 ms |
12656 KB |
Output is correct |
20 |
Correct |
98 ms |
12592 KB |
Output is correct |
21 |
Correct |
12 ms |
12500 KB |
Output is correct |
22 |
Correct |
13 ms |
12500 KB |
Output is correct |
23 |
Correct |
12 ms |
12456 KB |
Output is correct |
24 |
Correct |
11 ms |
12500 KB |
Output is correct |
25 |
Execution timed out |
2077 ms |
25312 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
11988 KB |
Output is correct |
3 |
Execution timed out |
2076 ms |
24060 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12060 KB |
Output is correct |
5 |
Correct |
7 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12060 KB |
Output is correct |
8 |
Correct |
7 ms |
12056 KB |
Output is correct |
9 |
Correct |
7 ms |
12056 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
7 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
12060 KB |
Output is correct |
13 |
Correct |
6 ms |
12088 KB |
Output is correct |
14 |
Correct |
9 ms |
12056 KB |
Output is correct |
15 |
Correct |
8 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
12056 KB |
Output is correct |
17 |
Correct |
7 ms |
11988 KB |
Output is correct |
18 |
Correct |
121 ms |
12620 KB |
Output is correct |
19 |
Correct |
105 ms |
12656 KB |
Output is correct |
20 |
Correct |
98 ms |
12592 KB |
Output is correct |
21 |
Correct |
12 ms |
12500 KB |
Output is correct |
22 |
Correct |
13 ms |
12500 KB |
Output is correct |
23 |
Correct |
12 ms |
12456 KB |
Output is correct |
24 |
Correct |
11 ms |
12500 KB |
Output is correct |
25 |
Correct |
7 ms |
11972 KB |
Output is correct |
26 |
Correct |
116 ms |
12624 KB |
Output is correct |
27 |
Correct |
119 ms |
12560 KB |
Output is correct |
28 |
Correct |
118 ms |
12552 KB |
Output is correct |
29 |
Correct |
119 ms |
12540 KB |
Output is correct |
30 |
Correct |
18 ms |
12328 KB |
Output is correct |
31 |
Correct |
23 ms |
12244 KB |
Output is correct |
32 |
Correct |
20 ms |
12372 KB |
Output is correct |
33 |
Correct |
21 ms |
12244 KB |
Output is correct |
34 |
Execution timed out |
2077 ms |
25312 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |