結果
| 問題 |
No.872 All Tree Path
|
| コンテスト | |
| ユーザー |
onakaT_Titai
|
| 提出日時 | 2019-06-15 16:45:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,981 bytes |
| コンパイル時間 | 1,057 ms |
| コンパイル使用メモリ | 105,644 KB |
| 実行使用メモリ | 20,864 KB |
| 最終ジャッジ日時 | 2024-11-19 01:36:10 |
| 合計ジャッジ時間 | 6,742 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 5 RE * 7 |
ソースコード
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
const double EPS = (1e-10);
using namespace std;
using Int = long long;
//using namespace boost::multiprecision;
const Int MOD = 1000000007;
long long mod_pow(long long x, long long n) {
long long res = 1;
for(int i = 0;i < 60; i++){
if(n >> i & 1) res = res * x % MOD;
x = x * x % MOD;
}
return res;
}
template<typename T>
T gcd(T a, T b) {
return b != 0 ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
return a * b / gcd(a, b);
}
void fast_input() {
cin.tie(0);
ios::sync_with_stdio(false);
}
struct Edge{
int from, to, cost;
};
int v[100005];
int childCnt[100005];
vector<vector<Edge>> G;
int dfs(int crt) {
v[crt] = 1;
int numOfChild = 0;
for (int i = 0; i < G[crt].size(); i++) {
if (v[G[crt][i].to] == 0) {
numOfChild += dfs(G[crt][i].to) + 1;
}
}
return childCnt[crt] = numOfChild;
}
int main(void) {
int N; cin >> N;
G = vector<vector<Edge>>(N);
for (int i = 0; i < N-1; i++) {
int u, v, w; cin >> u >> v >> w;
u--, v--;
G[u].push_back({u, v, w});
G[v].push_back({v, u, w});
}
dfs(0);
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < G[i].size(); j++) {
Edge e = G[i][j];
int weight = min(childCnt[e.from], childCnt[e.to]) + 1;
weight *= (N - weight);
weight *= e.cost;
ans += weight;
}
}
cout << ans << endl;
}
onakaT_Titai