結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 247 ms
23,552 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 247 ms
24,360 KB
testcase_14 AC 266 ms
24,336 KB
testcase_15 AC 259 ms
24,356 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 253 ms
24,320 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);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    set<pll> s;
    map<ll,ll> m;
    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){
        ll dec=0;
        for(auto x:to[i]){
            dec+=b[x];
        }
        s.insert({-a[i]+b[i]*to[i].size()+dec,i});
        m[i]=-a[i]+b[i]*to[i].size()+dec;
    }
    ll tot=0;
    while(s.size()){
        pll val=*s.begin();
        if(val.fi>=0){
            s.erase(val);
            continue;
        }
        for(auto x:to[val.se]){
            if(del[x]) continue;
            s.erase({m[x],x});
            m[x]-=b[x];
            s.insert({m[x],x});
        }
        s.erase(val);
        del[val.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