結果

問題 No.1488 Max Score of the Tree
ユーザー MZKiMZKi
提出日時 2021-04-06 13:24:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,580 bytes
コンパイル時間 1,535 ms
コンパイル使用メモリ 158,452 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-31 01:07:04
合計ジャッジ時間 3,369 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

struct edge{
    ll to, cost;
};

vector<int> cnt(110);
vector<P> vec;

void dfs(const vector<vector<edge>> &G, int v, int p){
    int ans = 0;
    for(auto nv : G[v]){
        if(nv.to == p)continue;
        dfs(G, nv.to, v);
        ans += cnt[nv.to];
        vec.push_back({nv.cost * cnt[nv.to], nv.cost});
    }
    cnt[v] = ans;
    if(ans == 0)cnt[v]++;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<vector<edge>> G(n);
    rep(i, n-1){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    dfs(G, 0, -1);
    vector<P> s;
    rep(i, n-1){
        s.push_back({vec[i].first/vec[i].second, vec[i].second});
    }
    sort(rall(s));
    int ans = 0, sum = 0;
    rep(i, n-1){
        if(sum + s[i].second <= k){
            ans += s[i].first * s[i].second;
            sum += s[i].second;
        }
        ans += s[i].first * s[i].second;
    }
    cout << ans << endl;
}
0