#include using namespace std; #define debug(n) cerr << #n << ':' << n << endl; #define dline cerr << __LINE__ << endl; using ll = long long; template using P = pair; template using Heap = priority_queue; template using heaP = priority_queue,greater>; template using umap = unordered_map; template using uset = unordered_set; template bool ChangeMax(T&a,const T&b){ if(a >= b) return false; a = b; return true; } template bool ChangeMin(T&a,const T&b){ if(a <= b) return false; a = b; return true; } template void Fill(T (&a)[N], const U&v){ fill((U*)a,(U*)(a+N),v); } template istream& operator >> (istream&is, vector&v){ for(auto&e:v)is >> e; return is; } struct Scc{ int vsize,esize; vector> ne,re; vector od,cs; vector used; Scc(vector>g,int vs,int es): vsize(vs),esize(es),ne(g),re(vs),cs(vs,-1),used(vs,false) { for(int i = 0; i < vsize; ++i){ for(auto&e:ne[i]){ re[e].push_back(i); } } for(int i = 0; i < vsize; ++i)dfs(i); reverse(od.begin(),od.end()); int y = 0; for(int e:od){ if(cs[e] != -1)continue; rdfs(e,y); y++; } } int operator[](int idx){ return cs[idx]; } void dfs(int x){ if(used[x]) return; used[x] = 1; for(auto&e:ne[x])dfs(e); od.push_back(x); } void rdfs(int x,int y){ if(cs[x] != -1)return; cs[x] = y; for(auto&e:re[x])rdfs(e,y); } }; int main(){ int n; cin >> n; vector> g(n); vector level(n); for(int i = 0; i < n; ++i){ int a,b; cin >> a >> b; b--; g[i].push_back(b); level[i] = a; } Scc scc(g,n,n); set st; double sum = 0; for(int i = 0; i < n; ++i){ int cs = scc.cs[i]; if(st.count(cs) == 0)sum += level[i]; else sum += level[i]/2; st.insert(scc.cs[g[i][0]]); } cout << fixed << setprecision(1) << sum << endl; return 0; }