답안 #987661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987661 2024-05-23T09:53:49 Z Otalp Cat Exercise (JOI23_ho_t4) C++14
31 / 100
2000 ms 24180 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long



vector<int> q[200100];
int p[200100], sz[200100];
ll mx[200100];
ll dp[200100];
int jmp[200100][30];
int tin[200100], tout[200100], timer = 0;
int h[200100];
int pos[200100];
int a[200100];


int get(int a){
    if(p[a] == a) return a;
    return p[a] = get(p[a]);
}

void un(int x, int y){
    x = get(x);
    y = get(y);
    if(x == y) return;
    if(sz[x] > sz[y]) swap(x, y);
    p[y] = p[x];
    sz[x] += sz[y];
    if(a[mx[x]] < a[mx[y]]) mx[x] = mx[y];
}


ll dfs(int v, int p, int k, int h){
    ll res = dp[v] + k;
    for(int to: q[v]){
        if(to == p or a[to] > a[h]) continue;
        res = max(dfs(to, v, k + 1, h), res);
    }
    return res;
}


void solve(){
    int n;
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        p[i] = i;
        mx[i] = i;
        pos[a[i]] = i;
        sz[i] = 1;
        dp[i] = 0;
    }
    for(int i=1; i<n; i++){
        int l, r;
        cin>>l>>r;
        q[l].pb(r);
        q[r].pb(l);
    }
    for(int i=1; i<=n; i++){
        vector<int> d;
        int v = pos[i];
        dp[v] = dfs(v, 0, 0, v);
    }
    cout<<dp[pos[n]]<<'\n';
}

int main(){
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12376 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Correct 3 ms 12340 KB Output is correct
4 Correct 3 ms 12380 KB Output is correct
5 Correct 3 ms 12376 KB Output is correct
6 Correct 4 ms 12380 KB Output is correct
7 Correct 3 ms 12380 KB Output is correct
8 Correct 3 ms 12380 KB Output is correct
9 Correct 4 ms 12376 KB Output is correct
10 Correct 3 ms 12380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12376 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Correct 3 ms 12340 KB Output is correct
4 Correct 3 ms 12380 KB Output is correct
5 Correct 3 ms 12376 KB Output is correct
6 Correct 4 ms 12380 KB Output is correct
7 Correct 3 ms 12380 KB Output is correct
8 Correct 3 ms 12380 KB Output is correct
9 Correct 4 ms 12376 KB Output is correct
10 Correct 3 ms 12380 KB Output is correct
11 Correct 4 ms 12380 KB Output is correct
12 Correct 4 ms 12376 KB Output is correct
13 Correct 4 ms 12376 KB Output is correct
14 Correct 3 ms 12376 KB Output is correct
15 Correct 4 ms 12432 KB Output is correct
16 Correct 4 ms 12376 KB Output is correct
17 Correct 4 ms 12380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12376 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Correct 3 ms 12340 KB Output is correct
4 Correct 3 ms 12380 KB Output is correct
5 Correct 3 ms 12376 KB Output is correct
6 Correct 4 ms 12380 KB Output is correct
7 Correct 3 ms 12380 KB Output is correct
8 Correct 3 ms 12380 KB Output is correct
9 Correct 4 ms 12376 KB Output is correct
10 Correct 3 ms 12380 KB Output is correct
11 Correct 4 ms 12380 KB Output is correct
12 Correct 4 ms 12376 KB Output is correct
13 Correct 4 ms 12376 KB Output is correct
14 Correct 3 ms 12376 KB Output is correct
15 Correct 4 ms 12432 KB Output is correct
16 Correct 4 ms 12376 KB Output is correct
17 Correct 4 ms 12380 KB Output is correct
18 Correct 92 ms 12888 KB Output is correct
19 Correct 92 ms 12892 KB Output is correct
20 Correct 85 ms 12900 KB Output is correct
21 Correct 7 ms 12892 KB Output is correct
22 Correct 8 ms 12892 KB Output is correct
23 Correct 8 ms 12892 KB Output is correct
24 Correct 8 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12376 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Correct 3 ms 12340 KB Output is correct
4 Correct 3 ms 12380 KB Output is correct
5 Correct 3 ms 12376 KB Output is correct
6 Correct 4 ms 12380 KB Output is correct
7 Correct 3 ms 12380 KB Output is correct
8 Correct 3 ms 12380 KB Output is correct
9 Correct 4 ms 12376 KB Output is correct
10 Correct 3 ms 12380 KB Output is correct
11 Correct 4 ms 12380 KB Output is correct
12 Correct 4 ms 12376 KB Output is correct
13 Correct 4 ms 12376 KB Output is correct
14 Correct 3 ms 12376 KB Output is correct
15 Correct 4 ms 12432 KB Output is correct
16 Correct 4 ms 12376 KB Output is correct
17 Correct 4 ms 12380 KB Output is correct
18 Correct 92 ms 12888 KB Output is correct
19 Correct 92 ms 12892 KB Output is correct
20 Correct 85 ms 12900 KB Output is correct
21 Correct 7 ms 12892 KB Output is correct
22 Correct 8 ms 12892 KB Output is correct
23 Correct 8 ms 12892 KB Output is correct
24 Correct 8 ms 12892 KB Output is correct
25 Correct 3 ms 12212 KB Output is correct
26 Correct 89 ms 12904 KB Output is correct
27 Correct 97 ms 12844 KB Output is correct
28 Correct 90 ms 12884 KB Output is correct
29 Correct 93 ms 12884 KB Output is correct
30 Correct 12 ms 12632 KB Output is correct
31 Correct 15 ms 12636 KB Output is correct
32 Correct 13 ms 12636 KB Output is correct
33 Correct 15 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12376 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Correct 3 ms 12340 KB Output is correct
4 Correct 3 ms 12380 KB Output is correct
5 Correct 3 ms 12376 KB Output is correct
6 Correct 4 ms 12380 KB Output is correct
7 Correct 3 ms 12380 KB Output is correct
8 Correct 3 ms 12380 KB Output is correct
9 Correct 4 ms 12376 KB Output is correct
10 Correct 3 ms 12380 KB Output is correct
11 Correct 4 ms 12380 KB Output is correct
12 Correct 4 ms 12376 KB Output is correct
13 Correct 4 ms 12376 KB Output is correct
14 Correct 3 ms 12376 KB Output is correct
15 Correct 4 ms 12432 KB Output is correct
16 Correct 4 ms 12376 KB Output is correct
17 Correct 4 ms 12380 KB Output is correct
18 Correct 92 ms 12888 KB Output is correct
19 Correct 92 ms 12892 KB Output is correct
20 Correct 85 ms 12900 KB Output is correct
21 Correct 7 ms 12892 KB Output is correct
22 Correct 8 ms 12892 KB Output is correct
23 Correct 8 ms 12892 KB Output is correct
24 Correct 8 ms 12892 KB Output is correct
25 Execution timed out 2050 ms 24180 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12380 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Execution timed out 2021 ms 22352 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12376 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Correct 3 ms 12340 KB Output is correct
4 Correct 3 ms 12380 KB Output is correct
5 Correct 3 ms 12376 KB Output is correct
6 Correct 4 ms 12380 KB Output is correct
7 Correct 3 ms 12380 KB Output is correct
8 Correct 3 ms 12380 KB Output is correct
9 Correct 4 ms 12376 KB Output is correct
10 Correct 3 ms 12380 KB Output is correct
11 Correct 4 ms 12380 KB Output is correct
12 Correct 4 ms 12376 KB Output is correct
13 Correct 4 ms 12376 KB Output is correct
14 Correct 3 ms 12376 KB Output is correct
15 Correct 4 ms 12432 KB Output is correct
16 Correct 4 ms 12376 KB Output is correct
17 Correct 4 ms 12380 KB Output is correct
18 Correct 92 ms 12888 KB Output is correct
19 Correct 92 ms 12892 KB Output is correct
20 Correct 85 ms 12900 KB Output is correct
21 Correct 7 ms 12892 KB Output is correct
22 Correct 8 ms 12892 KB Output is correct
23 Correct 8 ms 12892 KB Output is correct
24 Correct 8 ms 12892 KB Output is correct
25 Correct 3 ms 12212 KB Output is correct
26 Correct 89 ms 12904 KB Output is correct
27 Correct 97 ms 12844 KB Output is correct
28 Correct 90 ms 12884 KB Output is correct
29 Correct 93 ms 12884 KB Output is correct
30 Correct 12 ms 12632 KB Output is correct
31 Correct 15 ms 12636 KB Output is correct
32 Correct 13 ms 12636 KB Output is correct
33 Correct 15 ms 12636 KB Output is correct
34 Execution timed out 2050 ms 24180 KB Time limit exceeded
35 Halted 0 ms 0 KB -