結果

問題 No.1221 木 *= 3
ユーザー tonyu0tonyu0
提出日時 2020-09-04 22:40:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 880 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 103,168 KB
実行使用メモリ 10,944 KB
最終ジャッジ日時 2023-08-17 20:20:14
合計ジャッジ時間 6,999 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 153 ms
10,544 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 147 ms
10,944 KB
testcase_14 AC 153 ms
10,924 KB
testcase_15 AC 154 ms
10,816 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 162 ms
10,748 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  vector<vector<int>> g(n);
  vector<int> con(n);
  rep(i, 0, n - 1) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
    con[u]++;
    con[v]++;
  }

  ll all = 0;
  rep(i, 0, n) all += con[i] * b[i];

  vector<bool> deleted(n);
  rep(i, 0, n) {
    ll add = a[i];
    for (int j : g[i]) {
      if (!deleted[j]) { add -= b[i] + b[j]; }
    }
    if (add > 0) {
      all += add;
      deleted[i] = true;
    }
  }
  cout << all << '\n';

  return 0;
}
0