Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <vector>
- #pragma comment(linker, "/STACK:100000000")
- #define N int(1e5)
- #define pb push_back
- using namespace std;
- typedef long long LL;
- vector<int> graph[N], cost[N];
- bool was[N];
- LL ans = 0;
- int n;
- int dfs(int v, int Cost)
- {
- int res = 1;
- was[v] = true;
- for (int i = 0; i < graph[v].size(); i++)
- {
- int u = graph[v][i];
- if (!was[u])
- {
- res += dfs(u, cost[v][i]);
- }
- }
- LL add = Cost;
- add *= res * (n - res);
- ans += add;
- return res;
- }
- int main()
- {
- cin >> n;
- for (int i = 1; i < n; i++)
- {
- int a, b, c;
- cin >> a >> b >> c;
- graph[a].pb(b);
- graph[b].pb(a);
- cost[a].pb(c);
- cost[b].pb(c);
- }
- dfs(1, 0);
- cout.precision(4);
- cout << fixed << double(ans) / ( LL(n) * (n - 1) / 2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement