結果
問題 | No.872 All Tree Path |
ユーザー | polyomino_24 |
提出日時 | 2019-09-20 22:58:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 127 ms / 3,000 ms |
コード長 | 1,662 bytes |
コンパイル時間 | 1,103 ms |
コンパイル使用メモリ | 127,728 KB |
実行使用メモリ | 26,808 KB |
最終ジャッジ日時 | 2023-10-12 20:53:04 |
合計ジャッジ時間 | 4,809 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 123 ms
15,416 KB |
testcase_01 | AC | 118 ms
15,356 KB |
testcase_02 | AC | 126 ms
15,384 KB |
testcase_03 | AC | 84 ms
26,808 KB |
testcase_04 | AC | 4 ms
8,084 KB |
testcase_05 | AC | 127 ms
15,412 KB |
testcase_06 | AC | 125 ms
15,380 KB |
testcase_07 | AC | 117 ms
15,388 KB |
testcase_08 | AC | 12 ms
8,792 KB |
testcase_09 | AC | 12 ms
8,836 KB |
testcase_10 | AC | 13 ms
8,880 KB |
testcase_11 | AC | 13 ms
8,948 KB |
testcase_12 | AC | 13 ms
8,828 KB |
testcase_13 | AC | 4 ms
8,088 KB |
testcase_14 | AC | 4 ms
8,108 KB |
testcase_15 | AC | 4 ms
8,108 KB |
testcase_16 | AC | 4 ms
8,068 KB |
testcase_17 | AC | 5 ms
8,092 KB |
testcase_18 | AC | 4 ms
8,116 KB |
testcase_19 | AC | 4 ms
8,292 KB |
ソースコード
#include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) //#define cerr if(false) cerr #ifdef DEBUG #define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__); #else #define show(...) 42 #endif using namespace std; using ll = long long; using pii = pair<int, int>; template <typename T, typename S> ostream& operator<<(ostream& os, pair<T, S> a) { os << '(' << a.first << ',' << a.second << ')'; return os; } template <typename T> ostream& operator<<(ostream& os, vector<T> v) { for (auto x : v) os << x << ' '; return os; } void debug() { cerr << '\n'; } template <typename H, typename... T> void debug(H a, T... b) { cerr << a; if (sizeof...(b)) cerr << ", "; debug(b...); } int n; ll ans; vector<pii>g[200005]; ll dfs(int s, int p){ ll res = 1; for(auto x :g[s]){ if(x.first == p)continue; ll e = x.second; ll z = dfs(x.first, s); res += z; show(s, x.first,e, z); ans += e * z * (n - z); } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n; rep(i,n-1){ int a, b, c; cin >> a >> b >> c; a--,b--; g[a].emplace_back(b,c); g[b].emplace_back(a,c); } dfs(0,-1); cout << ans * 2 << endl; }