답안 #868411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868411 2023-10-31T12:52:50 Z Cookie Magic Tree (CEOI19_magictree) C++14
0 / 100
916 ms 1048576 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("HCN.INP");
ofstream fout("HCN.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
//using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 9;
const int mxn = 1e5 + 5, mxq = 2e5 + 5, sq = 200, mxv = 2e6 + 5;
const ll inf = 1e17 + 5;
//const int base= (1 << 18);
int n, m, k;
vt<int>adj[mxn + 1];
int day[mxn + 1];
ll cost[mxn + 1], dp[21][mxn + 1];
bool ckmax(ll &a, ll b){
    a = max(a, b);
}
void dfs(int tme, int s){
    dp[tme][s] = dp[tme + 1][s];
    ll tot = 0;
    for(auto i: adj[s]){
        dfs(tme, i);
        tot += dp[tme][i];
    }
    ckmax(dp[tme][s], tot);
    if(day[s] == tme){
        ckmax(dp[tme][s], cost[s]);
    }
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> k;
    for(int i = 2; i <= n; i++){
        int p; cin >> p;
        adj[p].pb(i);
    }
    for(int i = 0; i < m; i++){
        int v; cin >> v;
        cin >> day[v] >> cost[v];
    }
    ll ans = 0;
    for(int i = k; i >= 1; i--){
        dfs(i, 1);
        for(int j = 1; j <= n; j++){
            ckmax(ans, dp[i][j]);
        }
    }
    cout << ans;
    return(0);
}

Compilation message

magictree.cpp: In function 'bool ckmax(long long int&, long long int)':
magictree.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
   32 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 916 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 22 ms 15440 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 11444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 856 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 916 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 12120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 916 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 916 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -