Topic links: codeforces - Minimum a Diameter Tree
We put the weight average molecular weight can be near to the edge of the leaves. Why is it correct?
Suppose we put a close to the right edge of the leaf to other points near the leaves, certainly increase.
If you give the non-leaf side, then the other between leaf through this side certainly increase.
AC Code:
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+10;
int n,s,deg[N],cnt;
signed main(){
cin>>n>>s;
for(int i=1,a,b;i<n;i++) scanf("%d %d",&a,&b),deg[a]++,deg[b]++;
for(int i=1;i<=n;i++) if(deg[i]==1) cnt++;
printf("%.10lf\n",2.0*s/cnt);
return 0;
}