Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include<queue>
  4. #include<string>
  5. #include<math.h>
  6. #include<algorithm>
  7. #include<unordered_map>
  8. using namespace std;
  9.  
  10.  
  11. unsigned long long a[200005];
  12. int p[200005];
  13.  
  14. int main()
  15. {
  16. unsigned long long n, m, x;
  17. cin >> n;
  18. p[0] = -1;
  19. for (int i = 1; i <= n; ++i)
  20. {
  21. cin >> x >> m;
  22. if (m == 0)
  23. {
  24. a[i] = a[p[x]];
  25. p[i] = p[p[x]];
  26. }
  27. else
  28. {
  29. a[i] = a[x] + m;
  30. p[i] = x;
  31. }
  32. }
  33. x = 0;
  34. for (int i = 1; i <= n; ++i)
  35. x += a[i];
  36. cout << x;
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement