import sys input = sys.stdin.readline def main(): N = int(input()) L = [] S = [] for i in range(N): l, s = map(int, input().split()) L.append(l) S.append(s) X = set() for i in range(N): for _ in range(N): i = S[i] - 1 a = i for _ in range(N): i = S[i] - 1 a = min(a, i, key=lambda x: L[x]) X.add(a) ans = 0 for i in range(N): if i in X: ans += L[i] else: ans += L[i] / 2 print(f'{ans:.1f}') if __name__ == '__main__': main()