Submission #945262

# Submission time Handle Problem Language Result Execution time Memory
945262 2024-03-13T15:29:03 Z vladilius Cat Exercise (JOI23_ho_t4) C++17
31 / 100
2000 ms 37712 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int msz = 2e5 + 5;
using pii = pair<int, int>;

vector<int> g[msz];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n; cin>>n;
    vector<int> a(n + 1);
    int s = 0;
    for (int i = 1; i <= n; i++){
        cin>>a[i];
        if (a[i] == n){
            s = i;
        }
    }
    for (int i = 1; i < n; i++){
        int a, b; cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<bool> used(n + 1);
    function<pii(int, int, int)> dfs = [&](int v, int d, int pr){
        int t = v, dist = d;
        for (int i: g[v]){
            if (used[i] || i == pr) continue;
            auto [mx, dd] = dfs(i, d + 1, v);
            if (a[mx] > a[t]){
                t = mx;
                dist = dd;
            }
        }
        pii ret = {t, dist};
        return ret;
    };
    function<ll(int)> f = [&](int v){
        used[v] = true;
        ll out = 0;
        for (int i: g[v]){
            if (used[i]) continue;
            auto [u, d] = dfs(i, 1, 0);
            out = max(out, d + f(u));
        }
        return out;
    };
    cout<<f(s)<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4968 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4968 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 155 ms 5936 KB Output is correct
19 Correct 139 ms 5920 KB Output is correct
20 Correct 146 ms 5972 KB Output is correct
21 Correct 4 ms 5724 KB Output is correct
22 Correct 3 ms 5464 KB Output is correct
23 Correct 3 ms 5712 KB Output is correct
24 Correct 4 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4968 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 155 ms 5936 KB Output is correct
19 Correct 139 ms 5920 KB Output is correct
20 Correct 146 ms 5972 KB Output is correct
21 Correct 4 ms 5724 KB Output is correct
22 Correct 3 ms 5464 KB Output is correct
23 Correct 3 ms 5712 KB Output is correct
24 Correct 4 ms 5468 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 128 ms 5760 KB Output is correct
27 Correct 124 ms 5764 KB Output is correct
28 Correct 128 ms 5812 KB Output is correct
29 Correct 130 ms 5812 KB Output is correct
30 Correct 8 ms 5464 KB Output is correct
31 Correct 13 ms 5212 KB Output is correct
32 Correct 9 ms 5212 KB Output is correct
33 Correct 15 ms 5424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4968 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 155 ms 5936 KB Output is correct
19 Correct 139 ms 5920 KB Output is correct
20 Correct 146 ms 5972 KB Output is correct
21 Correct 4 ms 5724 KB Output is correct
22 Correct 3 ms 5464 KB Output is correct
23 Correct 3 ms 5712 KB Output is correct
24 Correct 4 ms 5468 KB Output is correct
25 Execution timed out 2017 ms 37712 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Execution timed out 2087 ms 16304 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4968 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 155 ms 5936 KB Output is correct
19 Correct 139 ms 5920 KB Output is correct
20 Correct 146 ms 5972 KB Output is correct
21 Correct 4 ms 5724 KB Output is correct
22 Correct 3 ms 5464 KB Output is correct
23 Correct 3 ms 5712 KB Output is correct
24 Correct 4 ms 5468 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 128 ms 5760 KB Output is correct
27 Correct 124 ms 5764 KB Output is correct
28 Correct 128 ms 5812 KB Output is correct
29 Correct 130 ms 5812 KB Output is correct
30 Correct 8 ms 5464 KB Output is correct
31 Correct 13 ms 5212 KB Output is correct
32 Correct 9 ms 5212 KB Output is correct
33 Correct 15 ms 5424 KB Output is correct
34 Execution timed out 2017 ms 37712 KB Time limit exceeded
35 Halted 0 ms 0 KB -