#include #define int long long #define double long double #define REP(i, b) for(int i = 0; i < (b); i++) #define REPS(i, b) for(int i = 1; i <= (b); i++) #define ALL(v) (v).begin(), (v).end() #define fi first #define se second #define pb push_back #define mp make_pair using namespace std; using pi = pair; using vi = vector; using vd = vector; using vs = vector; using vb = vector; using vpi = vector; using vvi = vector; using vvb = vector; const int INF = 1e16; const int MOD = 1e9+7; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } vi node; int root(int x) { if(node[x] == x) return x; return node[x] = root(node[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); node[rx] = ry; } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(1); int N; cin >> N; vector>> s(N+1); s[0].fi = INF; vd L(N+1); REPS(i, N) { cin >> L[i]; int to; cin >> to; s[i].fi = L[i]; s[i].se = mp(to, i); } sort(ALL(s), greater<>()); #ifdef DEBUG cout << endl; REPS(i, N) cout << s[i].se.fi << " " << s[i].se.se << endl; cout << endl; #endif node.resize(N+1); REPS(i, N) node[i] = i; REPS(i, N) { if(root(s[i].se.fi) == s[i].se.se) continue; unite(s[i].se.se, s[i].se.fi); } #ifdef DEBUG REPS(i, N) cout << root(i) << " "; cout << endl; #endif double ans = 0; REPS(i, N) { if(root(i) == i) ans += L[i]; else ans += L[i]/2; } cout << ans << endl; }