一眼看去,这不是高斯消元吗?

然后发现数据范围是100000...

然后发现是DAG...直接拓扑序递推即可。

边(x, y,z)的贡献是P(x) * z / out[x]

 #include <cstdio>
#include <queue>
const int N = ; struct Edge {
int v, nex, len;
}edge[N << ]; int top; int in[N], topo[N], e[N], n, out[N];
double p[N]; inline void add(int x, int y, int z) {
top++;
edge[top].v = y;
edge[top].len = z;
edge[top].nex = e[x];
e[x] = top;
return;
} inline void topo_sort() {
std::queue<int> Q;
for(int i = ; i <= n; i++) {
if(!in[i]) {
Q.push(i);
}
}
int t = ;
while(!Q.empty()) {
int x = Q.front();
Q.pop();
topo[++t] = x;
for(int i = e[x]; i; i = edge[i].nex) {
int y = edge[i].v;
in[y]--;
if(!in[y]) {
Q.push(y);
}
}
}
return;
} int main() {
int m;
scanf("%d%d", &n, &m);
for(int i = , x, y, z; i <= m; i++) {
scanf("%d%d%d", &x, &y, &z);
add(x, y, z);
in[y]++;
out[x]++;
}
topo_sort();
p[] = 1.0;
double ans = 0.0;
for(int a = ; a <= n; a++) {
int x = topo[a];
for(int i = e[x]; i; i = edge[i].nex) {
int y = edge[i].v;
p[y] += p[x] / out[x];
ans += p[x] * edge[i].len / out[x];
}
}
printf("%.2lf", ans);
return ;
}

AC代码

最新文章

  1. web app开发利器 - iscroll4 解决方案
  2. C#基础-out与ref字段
  3. 团队作业-第一周-NABCD竞争性需求分析
  4. 去除手机端a标签等按下去背景色
  5. jiulianhuan 快速幂--矩阵快速幂
  6. day3 python 集合 文件
  7. linux源代码阅读笔记 free_page_tables()分析
  8. JAVA生成PDF文件
  9. spring中@param和mybatis中@param使用区别
  10. 从free命令看Linux内存管理
  11. (转)syslog日志等级
  12. c# RSA加密和解密
  13. 重新学习一次javascript;
  14. iOS开发之--UIImageView的animationImages动画
  15. 解决在IDEA 的Maven下 出现 Cannot access in offline mode 问题
  16. html5 canvas多个图像旋转
  17. python 爬虫 爬取序列博客文章列表
  18. Spring Security自定义GrantedAuthority前缀
  19. AIDL旅行记之开篇AIDL基本介绍
  20. warning: ignoring option PermSize=256m; support was removed in 8.0

热门文章

  1. Day 6-1计算机网络基础&amp;TCP/IP
  2. 使用 idea 产生错误The server time zone value &#39;&#214;&#208;&#185;&#250;&#177;&#234;&#215;&#188;&#202;&#177;&#188;&#228;&#39; is unrecognized
  3. python爬虫scrapy的LinkExtractor
  4. 规范化Normalization
  5. SQL 添加索引
  6. jQuery 操作input select,checkbox
  7. PHP——emjoin表情存入数据库
  8. C# int数组转string字符串
  9. D. Flood Fill 区间DP 或lcs匹配
  10. 「Splay」区间翻转