Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include<queue>
- #include<string>
- #include<math.h>
- #include<algorithm>
- #include<unordered_map>
- using namespace std;
- unsigned long long a[200005];
- int p[200005];
- int main()
- {
- unsigned long long n, m, x;
- cin >> n;
- p[0] = -1;
- for (int i = 1; i <= n; ++i)
- {
- cin >> x >> m;
- if (m == 0)
- {
- a[i] = a[p[x]];
- p[i] = p[p[x]];
- }
- else
- {
- a[i] = a[x] + m;
- p[i] = x;
- }
- }
- x = 0;
- for (int i = 1; i <= n; ++i)
- x += a[i];
- cout << x;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement