답안 #782766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782766 2023-07-14T09:08:54 Z thimote75 Cat Exercise (JOI23_ho_t4) C++14
31 / 100
2000 ms 18764 KB
#include <bits/stdc++.h>

using namespace std;

using idata = vector<int>;
using igrid = vector<idata>;

idata height;
idata pos;

idata dp;
igrid roads;

int solve (int node, int parent, int depth) {
    if (dp[node] == -1) return 0;
    int mx = depth + dp[node];

    for (int next : roads[node]) if (next != parent)
        mx = max(mx, solve(next, node, depth + 1));

    return mx;
}

int main () {
    int N;
    cin >> N;

    height.resize(N);
    pos.resize(N);
    for (int i = 0; i < N; i ++) {
        cin >> height[i]; height[i] --;
        pos[height[i]] = i;
    }
    roads.resize(N);
    for (int i = 1; i < N; i ++) {
        int a, b;
        cin >> a >> b;
        a --; b --;
        roads[a].push_back(b);
        roads[b].push_back(a);
    }
    dp.resize(N, -1);
    for (int i = 0; i < N; i ++) {
        dp[pos[i]] = 0;
        dp[pos[i]] = solve(pos[i], -1, 0);
    }

    cout << dp[pos[N - 1]] << endl;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 260 KB Output is correct
18 Correct 81 ms 952 KB Output is correct
19 Correct 70 ms 988 KB Output is correct
20 Correct 69 ms 972 KB Output is correct
21 Correct 4 ms 892 KB Output is correct
22 Correct 5 ms 784 KB Output is correct
23 Correct 5 ms 852 KB Output is correct
24 Correct 5 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 260 KB Output is correct
18 Correct 81 ms 952 KB Output is correct
19 Correct 70 ms 988 KB Output is correct
20 Correct 69 ms 972 KB Output is correct
21 Correct 4 ms 892 KB Output is correct
22 Correct 5 ms 784 KB Output is correct
23 Correct 5 ms 852 KB Output is correct
24 Correct 5 ms 852 KB Output is correct
25 Correct 1 ms 300 KB Output is correct
26 Correct 82 ms 800 KB Output is correct
27 Correct 74 ms 880 KB Output is correct
28 Correct 76 ms 844 KB Output is correct
29 Correct 79 ms 820 KB Output is correct
30 Correct 9 ms 700 KB Output is correct
31 Correct 12 ms 712 KB Output is correct
32 Correct 10 ms 596 KB Output is correct
33 Correct 12 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 260 KB Output is correct
18 Correct 81 ms 952 KB Output is correct
19 Correct 70 ms 988 KB Output is correct
20 Correct 69 ms 972 KB Output is correct
21 Correct 4 ms 892 KB Output is correct
22 Correct 5 ms 784 KB Output is correct
23 Correct 5 ms 852 KB Output is correct
24 Correct 5 ms 852 KB Output is correct
25 Execution timed out 2062 ms 18764 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 2068 ms 17204 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 260 KB Output is correct
18 Correct 81 ms 952 KB Output is correct
19 Correct 70 ms 988 KB Output is correct
20 Correct 69 ms 972 KB Output is correct
21 Correct 4 ms 892 KB Output is correct
22 Correct 5 ms 784 KB Output is correct
23 Correct 5 ms 852 KB Output is correct
24 Correct 5 ms 852 KB Output is correct
25 Correct 1 ms 300 KB Output is correct
26 Correct 82 ms 800 KB Output is correct
27 Correct 74 ms 880 KB Output is correct
28 Correct 76 ms 844 KB Output is correct
29 Correct 79 ms 820 KB Output is correct
30 Correct 9 ms 700 KB Output is correct
31 Correct 12 ms 712 KB Output is correct
32 Correct 10 ms 596 KB Output is correct
33 Correct 12 ms 596 KB Output is correct
34 Execution timed out 2062 ms 18764 KB Time limit exceeded
35 Halted 0 ms 0 KB -