#include <bits/stdc++.h>
#define task "TEST"
#define task2 "A"
#define pl pair<ll, ll>
#define pf push_front
#define pb push_back
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b, c) for (ll i=a; i<=b; i+=c)
#define FORE(i, a, b, c) for (int i=a; i>=b; i+=c)
#define VI vector<int>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int Mod = 1e9+7;
const int maxn = 3e5;
const ll Inf = 1e16;
ll a, b, val, res;
ll disX[maxn+1], disY[maxn+1];
vector<pl> adj[maxn+1];
void dfs(ll v, ll v2, ll type) {
for (auto [p, q] : adj[v]) {
if (p == v2) continue;
if (type == 1) disX[p] = disX[v] + q;
else disY[p] = disY[v] + q;
dfs(p, v, type);
}
}
ll max_score(int n, int x, int y, ll k, VI U, VI V, VI W) {
FOR(i, 0, n-1, 1) adj[U[i]].pb(mp(V[i], W[i]));
FOR(i, 0, n-1, 1) adj[V[i]].pb(mp(U[i], W[i]));
dfs(x, -1, 1); dfs(y, -1, 2);
ll arr[maxn+1];
FOR(i, 0, n-1, 1) arr[i] = min(disX[i], disY[i]);
sort(arr, arr + n); int j = 0;
while (k - arr[j] >= 0 and j < n) k -= arr[j++];
return j;
}
/*void Read()
{
}
void Solve()
{
cout << max_score(7, 0, 2, 10, {0, 0, 1, 2, 2, 5}, {1, 3, 2, 4, 5, 6}, {2, 3, 4, 2, 5, 3});
}
int main()
{
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
for (t=1; t--;)
{
Read(); Solve();
}
}*/