Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int n,req;
- cin >> n >> req;
- vector <int> graph[n];
- int val[n];
- int a;
- for(int i=0;i<n;i++){
- cin >> val[i];
- }
- int b;
- for(int i=1;i<n;i++){
- cin >> b;
- graph[b-1].push_back(i);
- }
- int count=0;
- for(int i=0;i<n;i++){
- int value = val[i];
- int sum = req - value;
- vector <int> children;
- for(int j=0;j<graph[i].size();j++){
- children.push_back(graph[i][j]);
- }
- for(int j=0;j<children.size();j++){
- for(int k=0;k<graph[children[j]].size();k++)
- children.push_back(graph[children[j]][k]);
- }
- for(int j=0;j<children.size();j++){
- for(int k=j+1;k<children.size();k++)
- if(val[children[j]]+val[children[k]]>=sum){
- count++;
- }
- }
- }
- cout << count << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement