結果

問題 No.1221 木 *= 3
ユーザー kyoprounokyoprouno
提出日時 2020-09-05 23:23:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,609 bytes
コンパイル時間 2,498 ms
コンパイル使用メモリ 188,936 KB
実行使用メモリ 13,512 KB
最終ジャッジ日時 2024-05-06 20:23:18
合計ジャッジ時間 6,774 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 179 ms
12,604 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 176 ms
13,512 KB
testcase_14 AC 178 ms
13,380 KB
testcase_15 AC 177 ms
13,508 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 187 ms
13,184 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

const ll mod=1e9+7;


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n),b(n);
    vector<pll> ind(n);
    rep(i,n){
        cin >> a[i];
        ind[i].fi=a[i];
        ind[i].se=i;
    }
    rep(i,n){
        cin >> b[i];
    }
    vector<ll> del(n);
    vector<vector<ll>> to(n);
    rep(i,n-1){
        ll u,v;
        cin >> u >> v;
        u--; v--;
        to[u].push_back(v);
        to[v].push_back(u);
    }
    ll sum=0;
    rep(i,n){
        sum+=to[i].size()*b[i];
    }
    ll tot=0;
    sort(ind.rbegin(),ind.rend());
    rep(i,n){
        ll cnt=0;
        ll dec=0;
        for(auto x:to[ind[i].se]){
            if(del[x]==0){
                cnt++;
                dec+=b[x];
            }
        }
        if(a[ind[i].se]-cnt*b[ind[i].se]-dec>0){
            del[ind[i].se]=1;
        }
    }
    rep(i,n){
        //cout << del[i] << endl;
    }
    rep(i,n){
        if(del[i]){
            tot+=a[i];
            continue;
        }
        ll cnt=0;
        for(auto x:to[i]){
            if(del[x]==0) cnt++;
        }
        tot+=cnt*b[i];
    }
    cout << tot << endl;
    return 0;
}
0