#include using namespace std; vector to; vector from; vector order; vector cmp; vector level; bitset<110> used; void dfs1(int x){ used[x] = 1; if(!used[to[x]])dfs1(to[x]); order.push_back(x); } void dfs2(int x, int y){ if(cmp[x]!=-1)return; cmp[x] = y; dfs2(from[x],y); } int main(){ int n; cin >> n; to.resize(n); from.resize(n); level.resize(n); for (int i = 0; i < n; i++) { cin >> level[i] >> to[i]; to[i]--; from[to[i]] = i; } for(int i = 0; i < n; ++i){ if(!used[i])dfs1(i); } cmp.resize(n,-1); reverse(order.begin(),order.end()); int y = 0; for(int e:order){ if(cmp[e] == -1){ dfs2(e,y); y++; } } double sum = 0; for(int i = 0; i < y; ++i){ vector v; for(int j = 0; j < n; ++j){ if(cmp[j] == i)v.push_back(level[j]); } sort(v.begin(),v.end()); sum += (v.size()==1?v[0]/2:v[0]); for(int i = 1; i < (int)v.size(); ++i){ sum += v[i]/2; } } cout << setprecision(2) << sum << endl; return 0; }