#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < int(n); i++) using namespace std; long long MOD = 1000000007; long long INF = 1000000000000000; //10^15 typedef long long ll; typedef unsigned long long ull; ll powMod(ll x, ll n) { if (n == 0) return 1; ll r = powMod(x, n / 2); if (n % 2 == 0) return (r * r) % MOD; return (r * r % MOD) * x % MOD; } int n, s; double l[110]; vector g[110]; bool visited[110], minflag; double sum, Min; void dfs(int i, double mi, int start) { visited[i] = true; sum += l[i]; rep(j, g[i].size()) { if (g[i][j] == start) { minflag = true; Min = mi; } if (!visited[g[i][j]]) { dfs(g[i][j], min(mi, l[g[i][j]]), start); } } } int main(void) { cin >> n; rep(i, n) { cin >> l[i] >> s; s--; g[s].push_back(i); } double ans = 0.0; rep(i, n) { minflag = false; sum = 0; if (!visited[i]) { dfs(i, l[i], i); if (minflag) ans += sum / 2 + Min / 2; else ans += sum / 2 + l[i] / 2; } } cout << std::fixed; cout << std::setprecision(1) << ans << endl; return 0; }