Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- //#include<bits/stdc++.h>
- using namespace std;
- const int maxn = 3e5 + 10;
- vector<int> graph[maxn];
- int salary[maxn];
- int parent[maxn];
- int n, B;
- int cnt;
- void dfs(int node) {
- if(node == 0) {
- return;
- }
- for(int i = 0; i < (int) graph[node].size(); i++) {
- int neighbour = graph[node][i];
- if(neighbour == parent[node]) {
- if(salary[node] > salary[neighbour]) {
- cnt++;
- salary[neighbour] = salary[node];
- dfs(neighbour);
- }
- }
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> n >> B;
- salary[0] = B;
- for(int i = 1; i <= n; i++) {
- int r, p;
- cin >> salary[i] >> p;
- parent[i] = p;
- graph[i].push_back(p);
- graph[p].push_back(i);
- }
- for(int i = 1; i <= n; i++) {
- cnt = 0;
- dfs(i);
- cout << cnt << "\n";
- }
- return 0;
- }
- /*
- 7
- 1 2
- 1 3
- 2 4
- 2 5
- 3 6
- 3 7
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement