結果
| 問題 |
No.872 All Tree Path
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-03-09 21:59:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 728 bytes |
| コンパイル時間 | 1,914 ms |
| コンパイル使用メモリ | 177,032 KB |
| 実行使用メモリ | 24,572 KB |
| 最終ジャッジ日時 | 2024-11-14 13:28:13 |
| 合計ジャッジ時間 | 5,419 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 WA * 7 |
ソースコード
#include<bits/stdc++.h>
#define endl enjoy_codeforces
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
int n;std::cin>>n;
std::vector<std::vector<std::pair<int,long long>>>g(n);
for(int i=0;i<n-1;i++){
int u,v;long long w;std::cin>>u>>v>>w;u--,v--;
g.at(u).emplace_back(v,w);
g.at(v).emplace_back(u,w);
}
long long ans=0;
auto dfs=[&](auto&&dfs,int x,int p)->int{
int sz=1;
for(auto&&e:g.at(x)){
int y;long long w;std::tie(y,w)=e;
if(y==p)continue;
int s=dfs(dfs,y,x);
ans+=2*s*(n-s)*w;
sz+=s;
}
return sz;
};
dfs(dfs,0,0);
std::cout<<ans<<'\n';
}
ngtkana