// #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using mint = modint998244353; // using mint = modint1000000007; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair; using pll = pair; using T = tuple; using G = vector>; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep2(i, a, b) for (ll i = a; i < (b); ++i) #define rrep2(i, a, b) for (ll i = a-1; i >= (b); --i) #define rep3(i, a, b, c) for (ll i = a; i < (b); i+=c) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define popcount __builtin_popcount #define popcountll __builtin_popcountll #define fi first #define se second #define UNIQUE(v) sort(rng(v)), v.erase(unique(rng(v)), v.end()) #define MIN(v) *min_element(rng(v)) #define MAX(v) *max_element(rng(v)) template bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,T b){if(a void printv(vector &v){rep(i,v.size())cout< void printvv(vector> &v){rep(i,v.size())rep(j,v[i].size())cout<> n; scc_graph g(n); G g2(n), grev(n); vector a(n); rep(i, n){ int s; cin >> a[i] >> s; s--; a[i] *= 2; g.add_edge(s, i); g2[s].emplace_back(i); grev[i].emplace_back(s); } auto scc = g.scc(); int ans = 0; for (auto vec: scc){ if (vec.size() == 1){ int u = vec[0]; int flag = 0; for(auto v: grev[u]){ if (v != u) flag++; } if (flag) ans += a[u]/2; else ans += a[u]; continue; } int sum = 0, min_s = INF; for (auto v: vec) sum += a[v]/2; for (auto v: vec) chmin(min_s, sum+a[v]/2); ans += min_s; } if (ans&1) cout << ans/2 << ".5" << endl; else cout << ans/2 << ".0" << endl; return 0; }