Ural 1371. Cargo Agency
来源:互联网 发布:出口产品责任险知乎 编辑:程序博客网 时间:2024/06/05 11:21
The author is lazy..
Code :
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<math.h>using namespace std;#define sf scanf#define pf printf#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)#define ll long long#define CLR(a) memset((a),0,sizeof((a)))#define bug(x) cerr << "line: " << __LINE__ << ' ' << #x << " =" << (x) << endl;#define nMax 500010int first[nMax],to[nMax],w[nMax],nxt[nMax],e;void addadge(int u,int v,int vl) {to[e]=v;w[e]=vl;nxt[e]=first[u];first[u]=e;e++;to[e]=u;w[e]=vl;nxt[e]=first[v];first[v]=e;e++;}ll ans;ll dp[nMax];int vis[nMax];ll son[nMax];void dfs(int u,int fa) {vis[u] = 1;dp[u] = 0;son[u] = 0;for(int i=first[u],v;i!=-1;i=nxt[i]) if(! vis[v = to[i]]) {dfs(v,u);dp[u] += dp[v] + son[v]*w[i];dp[v] += son[v]*w[i];son[u] += son[v];}son[u] ++;for(int i=first[u],v;i!=-1;i=nxt[i]) if(to[i] != fa) {v = to[i];ans += dp[v] * (son[u]-son[v]) * 2;}}int n;int main() {#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);#endifwhile(~sf("%d",&n)){for(int i=1;i<=n;i++) vis[i]=0,first[i]=-1;e = 0;for(int i=1,a,b,c;i<n;i++){sf("%d%d%d",&a,&b,&c);addadge(a,b,c);}ans = 0;dfs(1,-1);pf("%.4lf\n",(double)1.0*ans/n/(n-1));}return 0;}
- Ural 1371. Cargo Agency
- Timus 1371. Cargo Agency
- Cargo
- 配置Cargo
- hdu2263Heavy Cargo
- Maven Cargo
- cargo center
- UVA_544_Heavy Cargo
- Agency and the Semantic Web
- President Appoints Consumer Agency Chief
- URAL
- 【ural】
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- qt应用程序交叉编译到arm环境变量设置
- istringstream用法
- 正则表达式
- Linux查看用户的7个命令
- 使用 PHP 直接在共享内存中存储数据集
- Ural 1371. Cargo Agency
- dos下查看shal值和Md5步骤
- 每个程序员都应该学习使用Python或Ruby
- 4.11 《硬啃设计模式》 第28章 邮件自动处理系统?- 责任链模式(Chain of Responsibility Pattern)
- Linux基础数据结构——双向链表
- 解决Xcode4删除文件后missing file警告
- 几种任务调度的 Java 实现方法与比较
- 怎么利用asp木马取得管理权限
- ASM集群文件系统ACFS(ASM Cluster File System)