#include<bits/stdc++.h> #define LL long long #define debug usingnamespace std; //东方之珠 整夜未眠! constint N = 3e5+66;
int d[N];
structnode {int to, nex;}e[N<<1]; int head[N], cnt;
inlinevoidjiabian(int u, int v){ e[++ cnt].to = v; e[cnt].nex = head[u]; head[u] = cnt; }
inlineintdfs(int x, int fa){ int i; for (i = head[x]; i; i = e[i].nex) { int y = e[i].to; if (y == fa) continue; d[y] = d[x] + 1; dfs(y, x); } }
inlineintthestars(){ int i, j, k, n, m, res(0); cin >> n >> m; for (i = 1; i < n; ++ i) { int x, y; cin >> x >> y; jiabian(x, y); } dfs(1, 0); for (i = 2; i <= n; ++ i) { if (res < d[i]) { res = d[i]; } } if (m <= res) cout << m + 1; elseif (m >= res + 2 * (n - res - 1)) cout << n; else cout << res + (m - res)/2 + 1; return0; }
#include<bits/stdc++.h> #define int long long #define debug usingnamespace std; //东方之珠 整夜未眠! constint N = 3e5+66;
int f[N], a[N];
structnode {int to, nex;}e[N<<1]; int head[N<<1], cnt;
inlinevoidadd(int u, int v){ e[++ cnt].to = v; e[cnt].nex = head[u]; head[u] = cnt; }
inlinevoiddfs(int x, int fa){ int i, M(0), N(0); for (i = head[x]; i; i = e[i].nex) { int y = e[i].to; if (y == fa) continue; dfs(y, x); M = max(M, f[y]); N = max(N, f[y] - a[y]); } f[x] = max(M, N + a[x]); }
inlineintthestars(){ int i, j, k, n, m, res(0); cin >> n; for (i = 1; i < n; ++ i) { int x, y; cin >> x >> y; add(x, y); add(y, x); } for (i = 1; i <= n; ++ i) scanf ("%lld", &a[i]); dfs(1, 0); cout << (f[1] + f[1] - a[1]); fclose (stdin), fclose (stdout); return0; }
#include<bits/stdc++.h> #define LL long long #define debug usingnamespace std; //东方之珠 整夜未眠! constint N = 5e5+66; constdouble eps = 1e-7;
double w[N], f[N], g[N];
structnode {int to, nex; double val;}e[N<<1]; int head[N<<1], cnt;
inlinevoidadd(int x, int y, double z){ e[++ cnt].to = y; e[cnt].val = z; e[cnt].nex = head[x]; head[x] = cnt; }
inlinevoiddfs1(int x, int fa){ int i; f[x] = 1 - w[x]; for (i = head[x]; i; i = e[i].nex) { int y = e[i].to; if (y == fa) continue; dfs1(y, x); f[x] *= 1 - f[y] * e[i].val;//cong 0 tui dao 1 } f[x] = 1 - f[x]; //f[x] cong biao shi 0 bian cheng le biao shi 1 }
inlinevoiddfs2(int x, int fa){ int i; for (i = head[x]; i; i = e[i].nex) { int y = e[i].to; if (y == fa) continue; if (1 - f[y] * e[i].val < eps) g[y] = 1; else g[y] = 1 - (1 - f[y]) * (1 - (1 - (1 - g[x]) / (1 - f[y] * e[i].val)) * e[i].val); dfs2(y, x); } }
inlineintthestars(){ int i, j, k, x, y, n; double z, res(0); cin >> n; for (i = 1; i < n; ++ i) { scanf ("%d%d%lf", &x, &y, &z); add(x, y, z/100); add(y, x, z/100); } for(i = 1 ; i <= n ; i ++ ) scanf("%lf" , &w[i]) , w[i] /= 100; dfs1(1, 0); g[1] = f[1]; dfs2(1, 0); for (i = 1; i <= n; ++ i) res += g[i]; printf ("%.6lf\n" , res); return0; }