import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
{
Scanner in
= new Scanner
(System.
in); int n = in.nextInt(), count = 0, t, m;
int a[][] = new int[n + 1][2];
a[count][1] = 0;
a[count][0] = -1;
count++;
long sumr = 0;
for(int i = 0; i < n; i++){
t = in.nextInt();
m = in.nextInt();
if(m == 0){
a[count][1] = a[a[t][0]][1];
a[count][0] = a[a[t][0]][0];
}else{
a[count][1] = a[t][1] + m;
a[count][0] = t;
}
sumr += a[count][1];
count++;
}
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBNYWluCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCVNjYW5uZXIgaW4gPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoJCWludCBuID0gaW4ubmV4dEludCgpLCBjb3VudCA9IDAsIHQsIG07CgkJaW50IGFbXVtdID0gbmV3IGludFtuICsgMV1bMl07CgkJYVtjb3VudF1bMV0gPSAwOwoJCWFbY291bnRdWzBdID0gLTE7CgkJY291bnQrKzsKCQlsb25nIHN1bXIgPSAwOwoJCWZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewoJCQl0ID0gaW4ubmV4dEludCgpOwoJCQltID0gaW4ubmV4dEludCgpOwoJCQlpZihtID09IDApewoJCQkJYVtjb3VudF1bMV0gPSBhW2FbdF1bMF1dWzFdOwoJCQkJYVtjb3VudF1bMF0gPSBhW2FbdF1bMF1dWzBdOwoJCQl9ZWxzZXsKCQkJCWFbY291bnRdWzFdID0gYVt0XVsxXSArIG07CgkJCQlhW2NvdW50XVswXSA9IHQ7CgkJCX0KCQkJc3VtciArPSBhW2NvdW50XVsxXTsKCQkJY291bnQrKzsKCQl9CgkJU3lzdGVtLm91dC5wcmludGxuKHN1bXIpOwoJfQp9