CodeForces
来源:互联网 发布:中行外汇行情分析软件 编辑:程序博客网 时间:2024/06/15 22:45
先大喊:我是傻逼!
首先这个题很简单
n 个结点, n-1 条边, 不会出现环
我写 MLE 了,因为我很自信的在 dfs 里面判 v 的父结点的时候判成了第 1 个结点,所以,,GG
要是说求期望的话
推一下就能发现答案就是 到每个结点的概率之和
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <set>#include <map>#include <stack>#include <queue>#include <ctype.h>#include <vector>#include <algorithm>#define in freopen("in.txt", "r", stdin)#define out freopen("out.txt", "w", stdout)// cout << " === " << endl;using namespace std;typedef long long ll;const int maxn = 100000 + 7, INF = 0x7f7f7f7f, mod = 1e9+7;int n, vis[maxn];vector<int> a[maxn];double ans = 0;void init() { int u, v; for(int i = 0; i < n-1; ++i) { scanf("%d%d", &u, &v); a[u].push_back(v); a[v].push_back(u); }}void dfs(int x, double f) { vis[x] = 1; int m = a[x].size(), mm = a[x].size(); if(x != 1) m--; if(m == 0) return ; double t = (f * (1.0 / m)); for(int i = 0; i < mm; ++i) { if(vis[a[x][i]]) continue; ans += t; dfs(a[x][i], t); } return;}int main() { memset(vis, 0, sizeof vis); scanf("%d", &n); init(); dfs(1, 1.0); printf("%.15lf", ans); return 0;}
阅读全文
1 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 常用加密 以及解密方法(包含测试方法) DES Base64 AES
- 51Nod 1686(第K大区间)
- [编程题] 堆棋子
- 斐波那契数列
- 图的基本存储的基本方式一(邻接矩阵)
- CodeForces
- LeetCode No.24 Swap Nodes in Pairs
- 最简单的条件判断程序
- hdu 6133 树状数组+分类讨论
- 2017.08.18总结
- CF549C
- hdu 1556 Color the ball(区间更新,查询点)
- 2017年8月18日训练日记
- 公网ip访问服务器网站(博客)