from collections import defaultdict def solve(N, L, S): # union-find で分ける N が最大100なので多分大丈夫 rangen = list(range(N)) par = list(rangen) def find(x): if par[x] == x: return x else: par[x] = find(par[x]) return par[x] def union(x, y): x = find(x) y = find(y) if x == y: return par[x] = y for i in rangen: union(i, S[i]) G = defaultdict(list) for i in rangen: g = find(i) G[g].append(i) total = 0 # グループそれぞれの中で for ns in G.values(): # 閉路を検出 n = ns[0] visited = set() while n not in visited: visited.add(n) n = S[n] loop_start = n # 閉路の中で最低難度のステージを探す min_stage = n while True: if L[n] < L[min_stage]: min_stage = n n = S[n] if n == loop_start: break # ループ中最低難度のステージ以外は 1/2 して足す for n in ns: if n == min_stage: total += L[n] else: total += L[n] / 2 return '{:.1f}'.format(total) def main(): N = int(input()) L = [] S = [] for i in range(N): l, s = input().split() L.append(int(l)) S.append(int(s) - 1) print(solve(N, L, S)) if __name__ == '__main__': main()