#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; vector<int> W; vector<double> P; vector<int> mark; double ans = 0; void doit2(int node, double p, int dest) { if (node == dest) { ans += p; return; } doit2(W[node], p * P[node], dest); } void doit(int node) { if (mark[node] == 1) return; if (mark[node] == 2) { // found someone in the stack. It's a cycle starting there. doit2(W[node], P[node], node); } else { mark[node] = 2; // it's on the stack doit(W[node]); } mark[node] = 1; // out of the stack } int main() { int N; scanf("%d", &N); W.resize(N); P.resize(N); mark.resize(N); for (int i = 0; i < N; i++) { int p; scanf("%d %d", &W[i], &p); W[i]--; P[i] = (double)p/100.; } // each node is in at most one cycle. ans = 0.; for (int i = 0; i < N; i++) if (mark[i] == 0) { doit(i); } printf("%.2f\n", ans); /* Enter your code here. Read input from STDIN. Print output to STDOUT */ return 0; }