#include <algorithm>
#include <set>
#include <limits>
#include <utility>
#include <iostream>
#include <type_traits>
#include <vector>
#include <cstdint>
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2790"

template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); }
template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); }
constexpr unsigned int mod                  = 1000000007;
template<typename T> constexpr T inf_v      = std::numeric_limits<T>::max() / 4;
template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884};
template<typename F>
struct fixpoint : F
{
    fixpoint(F&& f) : F(std::forward<F>(f)) {}
    template<typename... Args>
    decltype(auto) operator()(Args&&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
// template<typename F>
// inline decltype(auto) mfp(F&& f) { return fixpoint<F>{std::forward<F>(f)}; }
auto mfp = [](auto&& f) { return [=](auto&&... args) { return f(f, std::forward<decltype(args)>(args)...); }; };

using i32   = int32_t;
using i64   = int64_t;
using u32   = uint32_t;
using u64   = uint64_t;
using uint  = unsigned int;
using usize = std::size_t;
using ll    = long long;
using ull   = unsigned long long;
using ld    = long double;
template<typename T, usize n>
using arr = T (&)[n];
template<typename T, usize n>
using c_arr = const T (&)[n];
template<typename T>
T in()
{
    T v;
    return std::cin >> v, v;
}
template<typename T, typename Uint, usize n, usize i>
T in_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type) { return in<T>(); }
template<typename T, typename Uint, usize n, usize i>
auto in_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type& szs)
{
    const usize s = (usize)szs[i];
    std::vector<decltype(in_v<T, Uint, n, i + 1>(szs))> ans(s);
    for (usize j = 0; j < s; j++) { ans[j] = in_v<T, Uint, n, i + 1>(szs); }
    return ans;
}
template<typename T, typename Uint, usize n>
auto in_v(c_arr<Uint, n> szs) { return in_v<T, Uint, n, 0>(szs); }
template<typename... Types>
auto in_t() { return std::tuple<std::decay_t<Types>...>{in<Types>()...}; }

template<typename T>
int out(const T& v) { return std::cout << v, 0; }
template<typename T>
int out(const std::vector<T>& v)
{
    for (usize i = 0; i < v.size(); i++) {
        if (i > 0) { std::cout << ' '; }
        out(v[i]);
    }
    return std::cout << "\n", 0;
}
template<typename T1, typename T2>
int out(const std::pair<T1, T2>& v) { return out(v.first), std::cout << ' ', out(v.second), 0; }
template<typename T, typename... Args>
int out(const T& v, const Args... args) { return out(v), std::cout << ' ', out(args...), 0; }
template<typename... Args>
int outln(const Args... args) { return out(args...), std::cout << '\n', 0; }
template<typename... Args>
void outel(const Args... args) { return out(args...), std::cout << std::endl, 0; }

template<typename Cost = usize>
struct edge
{
    using cost_type = Cost;
    usize u, v;
    Cost c;
    edge(const usize u, const usize v) : u{u}, v{v}, c{1} {}
    edge(const usize u, const usize v, const Cost& c) : u{u}, v{v}, c{c} {}
    operator usize() const { return v; }
    usize from() const { return u; }
    usize to() const { return v; }
    Cost cost() const { return c; }
    friend std::ostream& operator<<(std::ostream& os, const edge& e) { return os << e.u << "->" << e.v << ":" << e.c; }
};
template<typename Edge>
class base_graph
{
public:
    base_graph(const usize n) : v{n}, es(n), res(n) {}
    void add_edge(const usize u, const usize v, const bool bi = false)
    {
        es[u].emplace_back(u, v), res[v].emplace_back(v, u);
        if (bi) { es[v].emplace_back(v, u), res[u].emplace_back(u, v); }
    }
    template<typename Cost>
    void add_edge(const usize u, const usize v, const Cost& c, const bool bi = false)
    {
        es[u].emplace_back(u, v, c), res[v].emplace_back(v, u, c);
        if (bi) { es[v].emplace_back(v, u, c), res[u].emplace_back(u, v, c); }
    }
    std::vector<Edge>& operator[](const usize u) { return es[u]; }
    const std::vector<Edge>& operator[](const usize u) const { return es[u]; }
    std::vector<Edge>& from(const usize u) { return es[u]; }
    const std::vector<Edge>& from(const usize u) const { return es[u]; }
    std::vector<Edge>& to(const usize v) { return res[v]; }
    const std::vector<Edge>& to(const usize v) const { return res[v]; }
    usize size() const { return v; }

private:
    usize v;
    std::vector<std::vector<Edge>> es, res;
};
template<typename Edge>
using base_tree = base_graph<Edge>;
using graph     = base_graph<edge<>>;
using tree      = base_graph<edge<>>;
template<typename Cost>
using cost_graph = base_graph<edge<Cost>>;
template<typename Cost>
using cost_tree = base_graph<edge<Cost>>;
template<typename Edge = edge<>>
class centroid
{
public:
    centroid(const base_tree<Edge>& tree) : cs(tree.size())
    {
        const std::size_t sz = tree.size();
        std::vector<std::size_t> sub(sz, 1);
        std::vector<bool> used(sz, false);
        auto size = [&, sz](auto&& self, const std::size_t s, const std::size_t p) -> std::size_t {
            sub[s] = 1;
            for (const auto& e : tree[s]) {
                const std::size_t to = e.to();
                if (to == p or used[to]) { continue; }
                sub[s] += self(self, to, s);
            }
            return sub[s];
        };
        auto search = [&, sz](auto&& self, const std::size_t s, const std::size_t p, const std::size_t tot) -> std::size_t {
            for (const auto& e : tree[s]) {
                const std::size_t to = e.to();
                if (p == to or used[to]) { continue; }
                if (sub[to] * 2 > tot) { return self(self, to, s, tot); }
            }
            return s;
        };
        auto build = [&, sz](auto&& self, const std::size_t s, const std::size_t pc) -> std::size_t {
            const std::size_t tot = size(size, s, sz), c = search(search, s, sz, tot);
            used[c] = true;
            if (pc != sz) { cs.add_edge(pc, c); }
            for (const auto& e : tree[c]) {
                const std::size_t to = e.to();
                if (not used[to]) { self(self, to, c); }
            }
            return c;
        };
        build(build, 0, sz);
    }
    const tree& centros() const { return cs; }

private:
    tree cs;
};
int main()
{
    auto N   = in<usize>();
    auto gas = in_v<ll>({N});
    cost_graph<ll> g(N);
    for (usize i = 0; i < N - 1; i++) {
        const auto a = in<usize>() - 1;
        const auto b = in<usize>() - 1;
        const auto d = in<ll>();
        g.add_edge(a, b, d, true);
    }
    const auto cg = centroid<edge<ll>>{g}.centros();
    usize centor  = 0;
    for (; centor < N; centor++) {
        if (cg.to(centor).empty()) { break; }
    }
    usize ans = 1;
    std::vector<bool> used(N, false);
    mfp([&](auto&& dfs, usize c) -> void {
        used[c]        = true;
        const usize cn = g[c].size();
        std::vector<std::vector<ll>> sub_ups(cn);
        std::vector<std::vector<ll>> sub_downs(cn);
        for (usize i = 0; i < cn; i++) {
            const auto& e = g[c][i];
            usize to      = e.to();
            if (used[to]) { continue; }
            ll cost = e.cost();
            sub_downs[i].push_back(0LL);
            sub_ups[i].push_back(0LL);
            mfp([&](auto&& dfs, usize s, usize p, usize d, ll c, ll min) -> void {
                if (sub_downs[i].size() <= d) { sub_downs[i].push_back(-inf_v<ll>); }
                chmax(sub_downs[i][d], min);
                for (const auto& e : g[s]) {
                    const usize to = e.to();
                    if (to == p or used[to]) { continue; }
                    const ll cost = e.cost();
                    dfs(dfs, to, s, d + 1, c - cost + gas[s], std::min(min, c - cost + gas[s]));
                }
            })(to, c, 1, gas[c] - cost, std::min(gas[c] - cost, 0LL));
            mfp([&](auto&& dfs, usize s, usize p, usize d, ll c, ll min) -> void {
                if (sub_ups[i].size() <= d) { sub_ups[i].push_back(-inf_v<ll>); }
                if (min == 0) { chmax(sub_ups[i][d], c); }
                for (const auto& e : g[s]) {
                    const usize to = e.to();
                    if (to == p or used[to]) { continue; }
                    const ll cost = e.cost();
                    const ll nmin = std::min(0LL, min - (cost - gas[to]));
                    dfs(dfs, to, s, d + 1, c - cost + gas[to], nmin);
                }
            })(to, c, 1, -cost + gas[to], std::min(0LL, -cost + gas[to]));
        }
        usize dmax = 0;
        for (usize i = 0; i < cn; i++) { chmax(dmax, sub_downs[i].size()); }
        for (usize i = 0; i < cn; i++) {
            for (usize d = 1; d < sub_downs[i].size(); d++) {
                if (sub_downs[i][d] >= 0) { chmax(ans, d + 1); }
            }
            for (usize d = 1; d < sub_ups[i].size(); d++) {
                if (sub_ups[i][d] >= 0) { chmax(ans, d + 1); }
            }
        }
        for (usize i = 0; i < cn; i++) {
            for (int d = (int)sub_downs[i].size() - 1; d >= 1; d--) { chmax(sub_downs[i][d - 1], sub_downs[i][d]); }
        }
        std::vector<std::multiset<ll, std::greater<ll>>> sd(dmax);
        for (usize i = 0; i < cn; i++) {
            for (usize d = 0; d < sub_downs[i].size(); d++) { sd[d].insert(sub_downs[i][d]); }
        }
        for (usize i = 0; i < cn; i++) {
            for (usize d = 1; d < sub_downs[i].size(); d++) { sd[d].erase(sd[d].find(sub_downs[i][d])); }
            for (usize d = 1; d < sub_ups[i].size(); d++) {
                const ll up = sub_ups[i][d];
                usize inf = 0, sup = dmax;
                while (sup - inf > 1) {
                    const usize mid                                      = (inf + sup) / 2;
                    const ll down                                        = (sd[mid].empty() ? -inf_v<ll> : *sd[mid].begin());
                    (up + down >= 0 and not sd[mid].empty() ? inf : sup) = mid;
                }
                if (inf > 0) { chmax(ans, d + inf + 1); }
            }
            for (usize d = 1; d < sub_downs[i].size(); d++) { sd[d].insert(sub_downs[i][d]); }
        }
        for (const usize nc : cg[c]) { dfs(dfs, nc); }
    })(centor);
    outln(ans);
    return 0;
}



Measured memory_bytes: 53232