답안 #723639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723639 2023-04-14T06:51:21 Z dxz05 Magic Tree (CEOI19_magictree) C++17
47 / 100
1688 ms 1048576 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 100500;

vector<int> g[N];

vector<vector<ll>> dp;
pair<int, int> fruit[N];

void dfs(int v){
    dp[v][fruit[v].first] = fruit[v].second;

    for (int u : g[v]){
        dfs(u);
    }

    for (int t = 1; t < dp[v].size(); t++){
        for (int u : g[v]){
            dp[v][t] += dp[u][t];
        }
    }

    for (int t = 1; t < dp[v].size(); t++) dp[v][t] = max(dp[v][t], dp[v][t - 1]);

}

void solve(){
    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 1; i < n; i++){
        int p;
        cin >> p;
        --p;
        g[p].push_back(i);
    }

    map<int, int> mp;

    for (int i = 0; i < m; i++){
        int v, d, w;
        cin >> v >> d >> w;
        --v;
        mp[d];
        fruit[v] = MP(d, w);
    }

    mp[0];
    k = 0;
    for (auto &now : mp){
        now.second = ++k;
    }

    for (int i = 0; i < n; i++){
        fruit[i].first = mp[fruit[i].first];
    }

    dp.assign(n, vector<ll>(k + 1, 0));

    dfs(0);

    cout << dp[0].back() << endl;

}

int main() {
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    solve();

    return 0;
}

Compilation message

magictree.cpp: In function 'void dfs(int)':
magictree.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int t = 1; t < dp[v].size(); t++){
      |                     ~~^~~~~~~~~~~~~~
magictree.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int t = 1; t < dp[v].size(); t++) dp[v][t] = max(dp[v][t], dp[v][t - 1]);
      |                     ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 428 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5844 KB Output is correct
2 Correct 7 ms 5844 KB Output is correct
3 Correct 6 ms 5844 KB Output is correct
4 Runtime error 530 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 12236 KB Output is correct
2 Correct 63 ms 10560 KB Output is correct
3 Correct 66 ms 15008 KB Output is correct
4 Correct 43 ms 10908 KB Output is correct
5 Correct 60 ms 18236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 80 ms 26128 KB Output is correct
11 Correct 66 ms 18380 KB Output is correct
12 Correct 84 ms 28976 KB Output is correct
13 Correct 62 ms 24992 KB Output is correct
14 Correct 61 ms 32384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 127980 KB Output is correct
2 Correct 671 ms 607160 KB Output is correct
3 Correct 707 ms 610240 KB Output is correct
4 Correct 855 ms 788632 KB Output is correct
5 Correct 1688 ms 787468 KB Output is correct
6 Correct 865 ms 789392 KB Output is correct
7 Correct 850 ms 791464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 6 ms 5844 KB Output is correct
11 Correct 7 ms 5844 KB Output is correct
12 Correct 6 ms 5844 KB Output is correct
13 Runtime error 530 ms 1048576 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Runtime error 428 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -