What am I missing here?

#include <bits/stdc++.h>

#define ll long long

#define INF (int)1E9 + 5

using namespace std;

const int N = 1e5 + 5;

ll sum[N];

vector graph[N];

ll a[N];

ll dfs(ll v, ll cost, ll prev){

if(sum[v] == INF){

sum[v] = a[v];

for(auto nei : graph[v]){

if(nei != prev){

sum[v] += dfs(nei,cost,v);

}

}

}

return max(sum[v], cost);

}

int main(){

```
int t,n,s,d;
ll x;
cin >> t;
while(t--){
cin >> n >> x;
for(int i = 1; i <= N; i++){
sum[i] = INF;
graph[i].clear();
}
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n-1; i++){
cin >> s >> d;
graph[s].push_back(d);
}
cout << dfs(1,-x,0) << "\n";
}
```

}

After reading this thread, I changed the graph to undirected, (although I’m still not sure why a tree should be an undirected graph)

I’ve also tried to build several testcases on my own, but they all seem to give the correct output.

Any help would be greatly appreciated.