답안 #945575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945575 2024-03-14T04:59:54 Z vjudge1 Magic Tree (CEOI19_magictree) C++17
6 / 100
218 ms 8268 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, k; cin >> n >> m >> k;
    vector <vector<int>> G(n);
    for ( int i = 1; i < n; i++ ){
        int p; cin >> p;
        --p;
        G[p].pb(i);
    }
    vector <int> w(n), d(n);
    for ( int i = 0; i < m; i++ ){
        int d_, v, w_; cin >> v >> d_ >> w_;
        --v;
        w[v] = w_;
        d[v] = d_;
    }
    int opt = 0;
    for ( int mask = 0; mask < 1 << n; mask++ ){
        vector <int> dp(n);
        int cnt = 0;
        for ( int i = 0; i < n; i++ ){
            if ( mask >> i & 1 ){
                dp[i] = d[i];
                cnt += w[i];
            }
        }
        auto dfs = [&](auto dfs, int u) -> bool{
            bool ret = true;
            int mx = 0;
            for ( auto &v: G[u] ){
                ret &= dfs(dfs, v);
                chmax(mx, dp[v]);
            }
            if ( mx > dp[u] && (mask >> u & 1)){
                ret = false;
            }
            chmax(dp[u], mx);
            return ret;
        };
        chmax(opt, dfs(dfs, 0) * cnt);
    }
    cout << opt;

    cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 192 ms 432 KB Output is correct
3 Correct 183 ms 428 KB Output is correct
4 Correct 184 ms 600 KB Output is correct
5 Correct 213 ms 344 KB Output is correct
6 Correct 202 ms 344 KB Output is correct
7 Correct 218 ms 596 KB Output is correct
8 Correct 176 ms 432 KB Output is correct
9 Correct 186 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 6764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 192 ms 432 KB Output is correct
3 Correct 183 ms 428 KB Output is correct
4 Correct 184 ms 600 KB Output is correct
5 Correct 213 ms 344 KB Output is correct
6 Correct 202 ms 344 KB Output is correct
7 Correct 218 ms 596 KB Output is correct
8 Correct 176 ms 432 KB Output is correct
9 Correct 186 ms 428 KB Output is correct
10 Incorrect 29 ms 8268 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 192 ms 432 KB Output is correct
3 Correct 183 ms 428 KB Output is correct
4 Correct 184 ms 600 KB Output is correct
5 Correct 213 ms 344 KB Output is correct
6 Correct 202 ms 344 KB Output is correct
7 Correct 218 ms 596 KB Output is correct
8 Correct 176 ms 432 KB Output is correct
9 Correct 186 ms 428 KB Output is correct
10 Incorrect 3 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 192 ms 432 KB Output is correct
3 Correct 183 ms 428 KB Output is correct
4 Correct 184 ms 600 KB Output is correct
5 Correct 213 ms 344 KB Output is correct
6 Correct 202 ms 344 KB Output is correct
7 Correct 218 ms 596 KB Output is correct
8 Correct 176 ms 432 KB Output is correct
9 Correct 186 ms 428 KB Output is correct
10 Incorrect 21 ms 6748 KB Output isn't correct
11 Halted 0 ms 0 KB -