#include<bits/stdc++.h> #define MAX_N 800000 usingnamespace std; typedefdouble dnt; template <classT> inlinevoidread(T &x){ x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } int n; dnt p[MAX_N+5]; vector <int> G[MAX_N+5]; int id[MAX_N+5], tp[MAX_N+5]; boolcmp(constint &x, constint &y){return id[x] < id[y];} intmain(){ read(n); dnt A = 0, B = 0; for (int i = 1, u, v, type; i <= n*(n-1)/2; i++) { read(u), read(v), read(type), scanf("%lf", p+i); if (type > 1) read(id[i]), tp[id[i]] = type; G[u].push_back(i), G[v].push_back(i); } for (int u = 1; u <= n; u++) { dnt sA = 0, sB = 0; sort(G[u].begin(), G[u].end(), cmp); for (int l = 0, r = 1; l < (int)G[u].size(); l = r+1, r = l+1) { if (!id[G[u][l]]) {sA += p[G[u][l]], sB += 1-p[G[u][l]], r = l; continue;} for (; r < (int)G[u].size() && id[G[u][l]] == id[G[u][r]]; r++) ; r--; dnt ts = 0; for (int i = l; i <= r; i++) ts += p[G[u][i]]; if (tp[id[G[u][l]]] == 2) sA += ts, sB += (r-l)*ts+(r-l+1)*(1-ts); if (tp[id[G[u][l]]] == 3) sA += (r-l)*ts+(r-l+1)*(1-ts), sB += ts; } for (int l = 0, r = 1; l < (int)G[u].size(); l = r+1, r = l+1) { if (!id[G[u][l]]) { A += p[G[u][l]]*(sA-p[G[u][l]]); A += (1-p[G[u][l]])*(sB-(1-p[G[u][l]])); B += (1-p[G[u][l]])*(sA-p[G[u][l]]); B += p[G[u][l]]*(sB-(1-p[G[u][l]])); r = l; continue; } for (; r < (int)G[u].size() && id[G[u][l]] == id[G[u][r]]; r++) ; r--; dnt ts = 0; for (int i = l; i <= r; i++) ts += p[G[u][i]]; if (tp[id[G[u][l]]] == 2) for (int i = l; i <= r; i++) A += p[G[u][i]]*(sA-ts), A += (1-ts)*(r-l+sB-(r-l)*ts-(r-l+1)*(1-ts)), A += (ts-p[G[u][i]])*(r-l-1+sB-(r-l)*ts-(r-l+1)*(1-ts)), B += p[G[u][i]]*(r-l+sB-(r-l)*ts-(r-l+1)*(1-ts)), B += (1-ts)*(sA-ts)+(ts-p[G[u][i]])*(1+sA-ts); if (tp[id[G[u][l]]] == 3) for (int i = l; i <= r; i++) A += p[G[u][i]]*(sB-ts), A += (1-ts)*(r-l+sA-(r-l)*ts-(r-l+1)*(1-ts)), A += (ts-p[G[u][i]])*(r-l-1+sA-(r-l)*ts-(r-l+1)*(1-ts)), B += p[G[u][i]]*(r-l+sA-(r-l)*ts-(r-l+1)*(1-ts)), B += (1-ts)*(sB-ts)+(ts-p[G[u][i]])*(1+sB-ts); } } returnprintf("%.2lf\n", A/6-B/12), 0; }