Submission #935785

# Submission time Handle Problem Language Result Execution time Memory
935785 2024-02-29T14:15:43 Z anton Cat Exercise (JOI23_ho_t4) C++17
31 / 100
121 ms 2004 KB
#include<bits/stdc++.h>


using namespace std;
#define int long long
#define pii pair<int, int>
int n;

const int MAX_N = 5000;

vector<int> adj[MAX_N];
int H[MAX_N];
int score[MAX_N];


pii get_max(int u, int anc, int limit){
    pii res = {H[u], score[u]};

    for(auto e: adj[u]){
        if(e!=anc && H[e]<=limit){
            pii c=  get_max(e, u, limit);
            if(c.first>res.first){
                res= {c.first, c.second+1};
            }

        }
    }
    return res;
}


signed main(){
    cin>>n;

    vector<pii> pts;

    for(int i = 0; i<n; i++){
        cin>>H[i];
        pts.push_back({H[i], i});
    }


    for(int i = 0; i<n-1; i++){
        int a, b;
        cin>>a>>b;
        adj[a-1].push_back(b-1);
        adj[b-1].push_back(a-1);
    }

    sort(pts.begin(), pts.end());
    
    for(int i = 0; i<n; i++){
        int u = pts[i].second;
        for(auto v: adj[u]){
            if(H[v]<H[u]){
                score[u] = max(score[u], get_max(v, u, H[u]).second+1);
            }
        }
        //cout<<u<<" "<<score[u]<<endl;
    }

    cout<<score[pts.back().second]<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 89 ms 1124 KB Output is correct
19 Correct 77 ms 1140 KB Output is correct
20 Correct 77 ms 1316 KB Output is correct
21 Correct 5 ms 1112 KB Output is correct
22 Correct 5 ms 1116 KB Output is correct
23 Correct 5 ms 1116 KB Output is correct
24 Correct 4 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 89 ms 1124 KB Output is correct
19 Correct 77 ms 1140 KB Output is correct
20 Correct 77 ms 1316 KB Output is correct
21 Correct 5 ms 1112 KB Output is correct
22 Correct 5 ms 1116 KB Output is correct
23 Correct 5 ms 1116 KB Output is correct
24 Correct 4 ms 1116 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 121 ms 1048 KB Output is correct
27 Correct 109 ms 1108 KB Output is correct
28 Correct 95 ms 1104 KB Output is correct
29 Correct 95 ms 1012 KB Output is correct
30 Correct 10 ms 860 KB Output is correct
31 Correct 20 ms 860 KB Output is correct
32 Correct 12 ms 860 KB Output is correct
33 Correct 15 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 89 ms 1124 KB Output is correct
19 Correct 77 ms 1140 KB Output is correct
20 Correct 77 ms 1316 KB Output is correct
21 Correct 5 ms 1112 KB Output is correct
22 Correct 5 ms 1116 KB Output is correct
23 Correct 5 ms 1116 KB Output is correct
24 Correct 4 ms 1116 KB Output is correct
25 Runtime error 7 ms 2004 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Runtime error 7 ms 2004 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 89 ms 1124 KB Output is correct
19 Correct 77 ms 1140 KB Output is correct
20 Correct 77 ms 1316 KB Output is correct
21 Correct 5 ms 1112 KB Output is correct
22 Correct 5 ms 1116 KB Output is correct
23 Correct 5 ms 1116 KB Output is correct
24 Correct 4 ms 1116 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 121 ms 1048 KB Output is correct
27 Correct 109 ms 1108 KB Output is correct
28 Correct 95 ms 1104 KB Output is correct
29 Correct 95 ms 1012 KB Output is correct
30 Correct 10 ms 860 KB Output is correct
31 Correct 20 ms 860 KB Output is correct
32 Correct 12 ms 860 KB Output is correct
33 Correct 15 ms 860 KB Output is correct
34 Runtime error 7 ms 2004 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -