結果
| 問題 |
No.872 All Tree Path
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2019-08-30 21:55:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,161 bytes |
| コンパイル時間 | 1,894 ms |
| コンパイル使用メモリ | 186,628 KB |
| 実行使用メモリ | 41,056 KB |
| 最終ジャッジ日時 | 2024-11-21 23:05:14 |
| 合計ジャッジ時間 | 10,650 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | AC * 7 RE * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000
int main(){
int N;
cin>>N;
vector<vector<pair<int,int>>> E(N,vector<pair<int,int>>());
vector<int> jisuu(N,0);
for(int i=0;i<N-1;i++){
int a,b,w;
cin>>a>>b>>w;
a--;b--;
E[a].emplace_back(b,w);
E[b].emplace_back(a,w);
jisuu[a]++;
jisuu[b]++;
}
queue<int> Q;
for(int i=0;i<N;i++){
if(jisuu[i]==1)Q.push(i);
}
map<pair<int,int>,int> M;
while(Q.size()!=0){
int now = Q.front();
Q.pop();
int cnt = 1;
int ind = -1;
for(int i=0;i<E[now].size();i++){
if(M[make_pair(now,E[now][i].first)]==0){
ind = E[now][i].first;
}
else{
cnt+=M[make_pair(now,E[now][i].first)];
}
}
M[make_pair(now,ind)]=cnt;
M[make_pair(ind,now)]=cnt;
jisuu[ind]--;
if(jisuu[ind]==1){
Q.push(ind);
}
}
long long ans = 0;
for(int i=0;i<N;i++){
for(int j=0;j<E[i].size();j++){
long long a = M[make_pair(i,E[i][j].first)];
long long x = a*(N-a);
x *= E[i][j].second;
ans += x;
}
}
cout<<ans<<endl;
return 0;
}
沙耶花