1. #pragma warning(disable:4786)
  2. //#pragma comment(linker, "/STACK:16777216")
  3. #pragma comment(linker, "/STACK:1073741824")
  4. #include<iostream>
  5. #include<cstdio>
  6. #include<algorithm>
  7. #include<vector>
  8. #include<set>
  9. #include<map>
  10. #include<functional>
  11. #include<string>
  12. #include<cstring>
  13. #include<cstdlib>
  14. #include<queue>
  15. #include<utility>
  16. #include<fstream>
  17. #include<sstream>
  18. #include<cmath>
  19. #include<stack>
  20. #include<assert.h>
  21. #include<complex>
  22. #include<bitset>
  23. using namespace std;
  24.  
  25. #define MEM(a, b) memset(a, (b), sizeof(a))
  26. #define CLR(a) memset(a, 0, sizeof(a))
  27. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  28. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  29. #define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
  30. #define S(X) ( (X) * (X) )
  31. #define SZ(V) (int )V.size()
  32. #define FORN(i, n) for(i = 0; i < n; i++)
  33. #define FORAB(i, a, b) for(i = a; i <= b; i++)
  34. #define ALL(V) V.begin(), V.end()
  35.  
  36. typedef pair<int,int> PII;
  37. typedef pair<double, double> PDD;
  38. typedef vector<int> VI;
  39.  
  40. #define IN(A, B, C) assert( B <= A && A <= C)
  41.  
  42. //typedef int LL;
  43. //typedef __int64 LL;
  44.  
  45. vector<int> Prime;
  46. int mark[50002];
  47.  
  48. void sieve(int n)
  49. {
  50. int i,j,limit=sqrt(n*1.)+2;
  51.  
  52. mark[1] = 1;
  53. for(i=4;i<=n;i+=2) mark[i]=1;
  54.  
  55. Prime.push_back(2);
  56. for(i=3;i<=n;i+=2)
  57. if(!mark[i])
  58. {
  59. Prime.push_back(i);
  60.  
  61. if(i<=limit)
  62. {
  63. for(j=i*i;j<=n;j+=i*2)
  64. {
  65. mark[j] = 1;
  66. }
  67. }
  68. }
  69. }
  70.  
  71.  
  72. VI V[200003];
  73. vector<PII> E[200003];
  74. int n, ans, dummy;
  75. vector<int>::iterator iV;
  76.  
  77. int xx;
  78.  
  79. void Binarize(int at, int parent)
  80. {
  81. int x, y, sz, i;
  82.  
  83. sz = V[at].size();
  84. // printf("%d %d\n", xx++, sz);
  85.  
  86. if(parent)
  87. {
  88. E[at].push_back(PII(parent, at<=n));
  89. }
  90.  
  91. if(sz <= 2)
  92. {
  93. for(i = 0; i < sz; i++)
  94. {
  95. if(at <= n)
  96. V[V[at][i]].erase( find(V[V[at][i]].begin(), V[V[at][i]].end(), at) );
  97.  
  98. E[at].push_back(PII(V[at][i], 1));
  99. Binarize(V[at][i], at);
  100. }
  101. }
  102. else
  103. {
  104. x = dummy + 1;
  105. y = dummy + 2;
  106. dummy += 2;
  107.  
  108. for(i = 0; i < sz; i++)
  109. {
  110. if(i < sz/2) V[x].push_back(V[at][i]);
  111. else V[y].push_back(V[at][i]);
  112.  
  113. if(at <= n)
  114. V[V[at][i]].erase( find(V[V[at][i]].begin(), V[V[at][i]].end(), at) );
  115. }
  116.  
  117. E[at].push_back( PII(x, 0) );
  118. E[at].push_back( PII(y, 0) );
  119.  
  120. Binarize(x, at);
  121. Binarize(y, at);
  122. }
  123. }
  124.  
  125. int subtree[200005], best_pos, best_value, best_d;
  126. int parent[200005], _sz;
  127.  
  128. int DFS(int at, int parent)
  129. {
  130. subtree[at] = 1;
  131. ::parent[at] = parent;
  132.  
  133. int here, sz = E[at].size(), i;
  134. for(i = 0; i < sz; i++)
  135. {
  136. if(E[at][i].first == parent)
  137. {
  138. here = E[at][i].second;
  139. continue;
  140. }
  141.  
  142. subtree[at] += DFS(E[at][i].first, at);
  143. }
  144.  
  145. if(parent && (best_pos == -1 || best_value > ABS(_sz/2 - subtree[at])))
  146. {
  147. best_pos = at, best_value = ABS(_sz/2 - subtree[at]), best_d = here;
  148. }
  149.  
  150. return subtree[at];
  151. }
  152.  
  153. void populate_depth(int at, int depth, int parent, vector<int> &V)
  154. {
  155. if(at <= n)
  156. V.push_back(depth);
  157.  
  158. int i, sz = E[at].size();
  159. for(i = 0; i < sz; i++)
  160. {
  161. if(E[at][i].first == parent) continue;
  162.  
  163. populate_depth(E[at][i].first, depth + E[at][i].second, at, V);
  164. }
  165. }
  166.  
  167. typedef complex<double> base;
  168. double PI = acos(-1.);
  169. void fft (vector<base> & a, bool invert) {
  170. int n = (int) a.size();
  171. for (int i=1, j=0; i<n; ++i) {
  172. int bit = n >> 1;
  173. for (; j>=bit; bit>>=1)
  174. j -= bit;
  175. j += bit;
  176. if (i < j)
  177. swap (a[i], a[j]);
  178. }
  179. for (int len=2; len<=n; len<<=1) {
  180. double ang = 2*PI/len * (invert ? -1 : 1);
  181. base wlen (cos(ang), sin(ang));
  182. for (int i=0; i<n; i+=len) {
  183. base w (1);
  184. for (int j=0; j<len/2; ++j) {
  185. base u = a[i+j], v = a[i+j+len/2] * w;
  186. a[i+j] = u + v;
  187. a[i+j+len/2] = u - v;
  188. w *= wlen;
  189. }
  190. }
  191. }
  192. if (invert)
  193. for (int i=0; i<n; ++i)
  194. a[i] /= n;
  195. }
  196.  
  197. void multiply (const vector<int> & a, const vector<int> & b, vector<int> & res) {
  198. vector<base> fa, fb;
  199. int i;
  200.  
  201. int sz = a.size();
  202. for(i = 0; i < sz; i++)
  203. fa.push_back( a[i] );
  204. sz = b.size();
  205. for(i = 0; i < sz; i++)
  206. fb.push_back( b[i] );
  207.  
  208. size_t n = 1;
  209. while (n < MAX (a.size(), b.size())) n <<= 1;
  210. n <<= 1;
  211. fa.resize (n), fb.resize (n);
  212. fft (fa, false), fft (fb, false);
  213. for (i=0; i<n; ++i)
  214. fa[i] *= fb[i];
  215. fft (fa, true);
  216. res.resize (n);
  217. for (i=0; i<n; ++i)
  218. res[i] = int (fa[i].real() + 0.5);
  219. }
  220.  
  221. void f(vector<int> &X, vector<int> &Y)
  222. {
  223. int i, maxx = 0;
  224. for(i = X.size() - 1; i >= 0; i--) maxx = MAX(X[i], maxx);
  225. for(i = Y.size() - 1; i >= 0; i--) maxx = MAX(Y[i], maxx);
  226.  
  227. vector<int> A(maxx + 1, 0), B(maxx + 1, 0), C;
  228. for(i = X.size() - 1; i >= 0; i--) A[X[i]]++;
  229. for(i = Y.size() - 1; i >= 0; i--) B[Y[i]]++;
  230.  
  231.  
  232. // printf(">>>>\n");
  233. // for(i = A.size() - 1; i >= 0; i--) printf("%d, ", A[i]); printf("\n");
  234. // for(i = B.size() - 1; i >= 0; i--) printf("%d, ", B[i]); printf("\n");
  235. multiply(A, B, C);
  236.  
  237. // for(i = C.size() - 1; i >= 0; i--) printf("%d, ", C[i]); printf("\n");
  238.  
  239. maxx = C.size();
  240. int sz = Prime.size();
  241. for(i = 0; i < sz && Prime[i] < maxx; i++)
  242. ans += C[Prime[i]];
  243. }
  244.  
  245. queue<PII> Q;
  246.  
  247. void isTree()
  248. {
  249. queue<int> Q;
  250. int vis[50004];
  251. int u, i;
  252.  
  253. MEM(vis, 0);
  254. vis[1] = 1;
  255. Q.push(1);
  256. while(!Q.empty())
  257. {
  258. u = Q.front();
  259. Q.pop();
  260.  
  261. for(i = V[u].size() - 1; i >= 0; i--)
  262. if(vis[V[u][i]]==0)
  263. {
  264. vis[V[u][i]] = 1;
  265. Q.push( V[u][i] );
  266. }
  267. }
  268.  
  269. for(i = 1; i <= n; i++)
  270. assert(vis[i]);
  271. }
  272.  
  273. int main()
  274. {
  275. int i, a, b, j;
  276. PII u;
  277. vector<int> X, Y;
  278.  
  279. sieve(50002);
  280.  
  281. scanf("%d", &n);
  282. IN(n, 2, 50000);
  283. for(i = 1; i < n; i++)
  284. {
  285. scanf("%d %d", &a, &b);
  286. IN(a, 1, n);
  287. IN(b, 1, n);
  288.  
  289. V[a].push_back(b);
  290. V[b].push_back(a);
  291. }
  292.  
  293. isTree();
  294.  
  295. dummy = n;
  296.  
  297. //Make the tree binary. If there is a node with many children, keep one child left and make other children
  298. //the children of the right node. make the cost to right child 0. other 1.
  299. //In this tree, the cost of the path from an original node to another original node is same.
  300. Binarize(1, 0);
  301.  
  302. /*
  303. printf("%d\n", ans);
  304. for(i = 1; i <= dummy; i++)
  305. {
  306. printf("%d:", i);
  307. for(j = 0; j < E[i].size(); j++)
  308. printf(" (%d, %d)", E[i][j].first, E[i][j].second);
  309. printf("\n");
  310. }
  311. */
  312.  
  313. //Now find center of the tree. center of the tree is a node, having <=n/3 nodes in each subtree if
  314. //this node is deleted.
  315. //Now delete the link to its parent. For each subtree solve recursively.
  316. //For inter subtree path, list up all the distances to the original nodes in each subtree. Find the solution using FFT
  317. int x, y;
  318.  
  319. int dd = 0;
  320. Q.push( PII(1, dummy) );
  321. while(!Q.empty())
  322. {
  323. u = Q.front();
  324. Q.pop();
  325.  
  326. _sz = u.second;
  327.  
  328. if(_sz == 1) continue;
  329.  
  330. best_pos = -1;
  331. best_value = u.second;
  332.  
  333. DFS(u.first, 0);
  334.  
  335. x = best_pos;
  336. y = parent[x];
  337.  
  338. E[x].erase( find(E[x].begin(), E[x].end(), PII(y, best_d)) );
  339. E[y].erase( find(E[y].begin(), E[y].end(), PII(x, best_d)) );
  340.  
  341. Q.push( PII(x, subtree[x]) );
  342. Q.push( PII(y, _sz - subtree[x]) );
  343.  
  344. X.clear();
  345. Y.clear();
  346.  
  347. populate_depth(x, 0, 0, X);
  348. populate_depth(y, 0, 0, Y);
  349.  
  350. if(best_d) for(i = X.size() - 1; i >= 0; i--) X[i]++;
  351. f(X, Y);
  352. }
  353.  
  354. // printf("%d\n", ans);
  355. double f = (1.*ans)/( (n*(n-1.))/2 );
  356. printf("%.12lf\n", f);
  357.  
  358. return 0;
  359. }