結果
問題 |
No.872 All Tree Path
|
ユーザー |
|
提出日時 | 2019-08-30 00:09:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 781 bytes |
コンパイル時間 | 1,741 ms |
コンパイル使用メモリ | 177,188 KB |
実行使用メモリ | 44,892 KB |
最終ジャッジ日時 | 2024-11-17 17:52:30 |
合計ジャッジ時間 | 54,452 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 6 TLE * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long N; vector<vector<pair<int,long long>>> edge; vector<long long> dist; void dfs(int from, int prev = -1){ for(int i = 0; i < edge[from].size(); ++i){ int to = edge[from][i].first; if(to==prev) continue; dist[to] = dist[from] + edge[from][i].second; dfs(to,from); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; edge.resize(N); dist.resize(N); for(int i = 0; i < N-1; ++i){ int u,v; long long w; cin >> u >> v >> w; u--,v--; edge[u].push_back({v,w}); edge[v].push_back({u,w}); } long long ans = 0; for(int i = 0; i < N; ++i){ for(int j = 0; j < N; ++j) dist[j] = 0; dfs(i,-1); ans += accumulate(dist.begin(),dist.end(),0LL); } cout << ans << endl; return 0; }