結果
問題 | No.872 All Tree Path |
ユーザー | 👑 kmjp |
提出日時 | 2019-08-30 21:29:07 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 170 ms / 3,000 ms |
コード長 | 1,122 bytes |
コンパイル時間 | 1,819 ms |
コンパイル使用メモリ | 171,092 KB |
実行使用メモリ | 27,720 KB |
最終ジャッジ日時 | 2024-05-01 16:42:48 |
合計ジャッジ時間 | 4,053 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 165 ms
16,128 KB |
testcase_01 | AC | 152 ms
16,256 KB |
testcase_02 | AC | 161 ms
16,324 KB |
testcase_03 | AC | 87 ms
27,720 KB |
testcase_04 | AC | 4 ms
8,192 KB |
testcase_05 | AC | 170 ms
16,256 KB |
testcase_06 | AC | 167 ms
16,300 KB |
testcase_07 | AC | 166 ms
16,256 KB |
testcase_08 | AC | 14 ms
9,088 KB |
testcase_09 | AC | 14 ms
9,020 KB |
testcase_10 | AC | 13 ms
9,088 KB |
testcase_11 | AC | 13 ms
8,916 KB |
testcase_12 | AC | 13 ms
9,032 KB |
testcase_13 | AC | 5 ms
8,252 KB |
testcase_14 | AC | 5 ms
8,176 KB |
testcase_15 | AC | 4 ms
8,068 KB |
testcase_16 | AC | 5 ms
8,176 KB |
testcase_17 | AC | 6 ms
8,192 KB |
testcase_18 | AC | 4 ms
8,064 KB |
testcase_19 | AC | 4 ms
8,064 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N; vector<pair<int,int>> E[202020]; int C[202020]; ll ret; int dfs(int cur,int pre) { C[cur]=1; int R=0; FORR(e,E[cur]) { if(e.first==pre) { R=e.second; } else { C[cur]+=dfs(e.first,cur); } } ret+=1LL*R*C[cur]*(N-C[cur]); return C[cur]; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N-1) { cin>>x>>y>>r; E[x-1].push_back({y-1,r}); E[y-1].push_back({x-1,r}); } dfs(0,-1); cout<<ret*2<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }