結果
| 問題 |
No.872 All Tree Path
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2019-08-30 21:30:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 751 bytes |
| コンパイル時間 | 1,841 ms |
| コンパイル使用メモリ | 173,512 KB |
| 実行使用メモリ | 22,340 KB |
| 最終ジャッジ日時 | 2024-11-21 21:59:30 |
| 合計ジャッジ時間 | 3,797 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
int n; cin >> n;
struct Edge { int to, w; };
VV<Edge> g(n);
for (int _ = 0; _ < n - 1; ++_) {
int u, v, w; cin >> u >> v >> w, --u, --v;
g[u].emplace_back(Edge{v, w});
g[v].emplace_back(Edge{u, w});
}
lint res = 0;
V<> sz(n);
auto dfs = [&](const auto& dfs, int v, int p) -> void {
sz[v] = 1;
for (const auto& e : g[v]) if (e.to != p) {
dfs(dfs, e.to, v);
res += sz[e.to] * (n - sz[e.to]) * e.w;
sz[v] += sz[e.to];
}
};
dfs(dfs, 0, -1);
cout << 2 * res << '\n';
}
risujiroh