#include #include using namespace std; int main(){ int n, p; cin >> n; vector L(n), P(n); vector used(n); atcoder::scc_graph g(n); for(int i = 0; i < n; i++){ cin >> L[i] >> P[i]; g.add_edge(--P[i], i); } int ans = 0; auto G = g.scc(); for(auto &&a : G){ bool vis = false; for(auto &&v : a){ if(used[P[v]])vis = true; } int minv = 400; for(auto &&v : a){ minv = min(minv, L[v]); ans += L[v]; used[v] = true; } if(!vis)ans += minv; } printf("%d.%d\n",ans/2,(ans&1?5:0)); }