結果

問題 No.1221 木 *= 3
ユーザー tonyu0tonyu0
提出日時 2020-09-04 22:45:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 839 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 110,664 KB
実行使用メモリ 11,488 KB
最終ジャッジ日時 2023-08-17 20:25:39
合計ジャッジ時間 4,769 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 152 ms
10,960 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 149 ms
11,200 KB
testcase_14 AC 155 ms
11,148 KB
testcase_15 AC 155 ms
11,356 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 160 ms
10,912 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iomanip>
#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)


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<ll> 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